:root {
  --primary: #0078d4;
  --primary-dark: #005a9e;
  --primary-light: #c7e0f4;
  --success: #107c10;
  --danger: #c50f1f;
  --warning: #d83b01;
  --bg: #f3f2f1;
  --surface: #ffffff;
  --border: #e1dfdd;
  --text: #201f1e;
  --text-muted: #605e5c;
  --text-light: #8a8886;
  --radius: 6px;
  --shadow: 0 2px 8px rgba(0,0,0,.12);
  --header-h: 52px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 16px; border-radius: var(--radius);
  border: 1px solid transparent; cursor: pointer;
  font-size: 14px; font-weight: 500; transition: background .15s, opacity .15s;
  white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary  { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover  { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-outline  { background: #fff; color: var(--primary); border-color: var(--primary); }
.btn-outline:hover  { background: var(--primary-light); }
.btn-ghost    { background: transparent; color: var(--text-muted); border-color: transparent; }
.btn-ghost:hover    { background: var(--border); color: var(--text); }
.btn-danger   { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover   { opacity: .88; }
.btn-microsoft { background: #fff; color: #201f1e; border: 1px solid var(--border); justify-content: center; padding: 10px 20px; font-size: 15px; box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.btn-microsoft:hover { background: #f8f8f8; }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-icon { padding: 5px; border-radius: 4px; background: transparent; border: none; cursor: pointer; color: var(--text-muted); }
.btn-icon:hover { background: var(--border); color: var(--text); }

/* ── Forms ── */
.form-group { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
label { font-weight: 500; font-size: 13px; color: var(--text); }
input[type=text], input[type=password], input[type=email],
input[type=datetime-local], input[type=number], select, textarea {
  padding: 7px 10px; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 14px;
  background: #fff; color: var(--text); width: 100%;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
}
.form-hint { font-size: 12px; color: var(--text-muted); }

/* ── Auth page ── */
.auth-page { background: var(--bg); min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.auth-container { width: 100%; max-width: 420px; padding: 16px; }
.auth-card { background: var(--surface); border-radius: 10px; box-shadow: var(--shadow); padding: 40px 36px; }
.auth-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; }
.auth-logo h1 { font-size: 20px; font-weight: 600; }
.auth-divider { text-align: center; margin: 18px 0; position: relative; color: var(--text-muted); font-size: 13px; }
.auth-divider::before, .auth-divider::after {
  content: ''; position: absolute; top: 50%; width: 38%; height: 1px; background: var(--border);
}
.auth-divider::before { left: 0; }
.auth-divider::after { right: 0; }
.auth-section .btn { width: 100%; justify-content: center; }
.auth-section .btn-primary { margin-top: 4px; }
.auth-hint { margin-top: 20px; text-align: center; font-size: 12px; color: var(--text-muted); }
.error-banner { background: #fde7e9; color: var(--danger); border: 1px solid #f1707a; border-radius: var(--radius); padding: 10px 14px; margin-bottom: 16px; font-size: 13px; }
.hidden { display: none !important; }

/* ── App header ── */
.app-header { background: var(--primary); color: #fff; height: var(--header-h); position: sticky; top: 0; z-index: 100; }
.header-inner { max-width: 1200px; margin: 0 auto; padding: 0 20px; height: 100%; display: flex; align-items: center; justify-content: space-between; }
.header-brand { display: flex; align-items: center; }
.brand-link { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 600; font-size: 16px; }
.brand-link:hover { text-decoration: none; opacity: .9; }
.header-nav { display: flex; align-items: center; gap: 12px; }
.nav-link { color: rgba(255,255,255,.85); font-size: 14px; }
.nav-link:hover { color: #fff; text-decoration: none; }
.user-greeting { color: rgba(255,255,255,.8); font-size: 13px; }
.header-nav .btn-ghost { color: rgba(255,255,255,.85); }
.header-nav .btn-ghost:hover { background: rgba(255,255,255,.15); color: #fff; }

/* ── Main content ── */
.main-content { max-width: 1200px; margin: 0 auto; padding: 28px 20px; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; flex-wrap: wrap; gap: 12px; }
.page-header h2 { font-size: 22px; font-weight: 600; }
.page-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ── Folder cards ── */
.folders-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.folder-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 18px; cursor: pointer; transition: box-shadow .15s, border-color .15s;
  display: flex; flex-direction: column; gap: 8px;
}
.folder-card:hover { box-shadow: var(--shadow); border-color: var(--primary-light); }
.folder-card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.folder-card-title { font-weight: 600; font-size: 15px; line-height: 1.3; }
.folder-card-meta { font-size: 12px; color: var(--text-muted); display: flex; flex-direction: column; gap: 2px; }
.folder-card-meta span { display: flex; align-items: center; gap: 4px; }
.folder-card-footer { display: flex; align-items: center; justify-content: space-between; margin-top: 4px; }
.photo-count { font-size: 12px; font-weight: 600; color: var(--primary); background: var(--primary-light); padding: 2px 8px; border-radius: 12px; }
.badge { font-size: 11px; padding: 2px 7px; border-radius: 12px; font-weight: 600; }
.badge-success { background: #dff6dd; color: var(--success); }
.badge-muted { background: var(--border); color: var(--text-muted); }
.badge-info { background: #dbeafe; color: #1d4ed8; }

/* ── Photo grid ── */
.photo-grid { columns: 3 220px; gap: 12px; }
.photo-item { break-inside: avoid; margin-bottom: 12px; position: relative; border-radius: var(--radius); overflow: hidden; cursor: pointer; }
.photo-item img { width: 100%; display: block; transition: transform .2s; }
.photo-item:hover img { transform: scale(1.02); }
.photo-item .photo-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0); transition: background .2s; display: flex; align-items: flex-end; padding: 8px; }
.photo-item:hover .photo-overlay { background: rgba(0,0,0,.35); }
.photo-item .photo-actions { opacity: 0; transition: opacity .2s; display: flex; gap: 6px; }
.photo-item:hover .photo-actions { opacity: 1; }
.photo-delete-btn { background: rgba(197,15,31,.9); color: #fff; border: none; border-radius: 4px; padding: 4px 8px; font-size: 12px; cursor: pointer; }
.photo-delete-btn:hover { background: var(--danger); }

/* ── Upload zone ── */
.upload-zone {
  border: 2px dashed var(--border); border-radius: 8px; padding: 40px 20px;
  text-align: center; color: var(--text-muted); cursor: pointer; transition: border-color .2s, background .2s;
  margin-bottom: 24px;
}
.upload-zone.drag-over { border-color: var(--primary); background: var(--primary-light); color: var(--primary); }
.upload-zone p { margin-top: 8px; font-size: 13px; }
.upload-zone input[type=file] { display: none; }
.upload-progress { background: var(--primary-light); border-radius: 4px; height: 6px; margin-top: 12px; overflow: hidden; display: none; }
.upload-progress-bar { height: 100%; background: var(--primary); transition: width .3s; width: 0%; }

/* ── Folder detail header ── */
.folder-detail-header { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 20px 24px; margin-bottom: 24px; }
.folder-detail-header h2 { font-size: 20px; font-weight: 600; margin-bottom: 6px; }
.folder-detail-meta { display: flex; flex-wrap: wrap; gap: 16px; color: var(--text-muted); font-size: 13px; }
.folder-detail-meta span { display: flex; align-items: center; gap: 5px; }

/* ── Modals ── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 200; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: var(--surface); border-radius: 10px; box-shadow: 0 8px 40px rgba(0,0,0,.2); width: 100%; max-width: 500px; max-height: 90vh; display: flex; flex-direction: column; }
.modal-lg { max-width: 740px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-close { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--text-muted); line-height: 1; padding: 2px 6px; border-radius: 4px; }
.modal-close:hover { background: var(--border); color: var(--text); }
.modal-body { padding: 20px 22px; overflow-y: auto; flex: 1; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; padding-top: 16px; border-top: 1px solid var(--border); margin-top: 16px; }

/* ── Lightbox ── */
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 300; display: flex; align-items: center; justify-content: center; }
.lightbox img { max-width: 90vw; max-height: 90vh; object-fit: contain; border-radius: 4px; }
.lightbox-close { position: absolute; top: 16px; right: 20px; font-size: 32px; color: #fff; cursor: pointer; opacity: .7; background: none; border: none; line-height: 1; }
.lightbox-close:hover { opacity: 1; }
.lightbox-nav { position: absolute; top: 50%; transform: translateY(-50%); font-size: 28px; color: #fff; cursor: pointer; background: rgba(255,255,255,.15); border: none; border-radius: 50%; width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; }
.lightbox-nav:hover { background: rgba(255,255,255,.3); }
.lightbox-prev { left: 16px; }
.lightbox-next { right: 16px; }
.lightbox-caption { position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%); color: rgba(255,255,255,.7); font-size: 13px; text-align: center; }

/* ── Calendar event list ── */
.event-list { display: flex; flex-direction: column; gap: 8px; max-height: 500px; overflow-y: auto; }
.event-item { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); gap: 12px; }
.event-item:hover { background: var(--bg); }
.event-info { flex: 1; min-width: 0; }
.event-subject { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.event-date { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.event-location { font-size: 12px; color: var(--text-muted); }

/* ── Admin tables ── */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th { text-align: left; padding: 10px 12px; font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; border-bottom: 2px solid var(--border); background: var(--bg); }
.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg); }
.table-card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }

/* ── Permission toggles ── */
.perm-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); gap: 12px; }
.perm-row:last-child { border-bottom: none; }
.perm-user { font-weight: 500; }
.perm-sub { font-size: 12px; color: var(--text-muted); }
.perm-toggles { display: flex; gap: 16px; }
.toggle-label { display: flex; align-items: center; gap: 6px; cursor: pointer; font-size: 13px; user-select: none; }
.toggle-label input[type=checkbox] { width: 15px; height: 15px; accent-color: var(--primary); cursor: pointer; }

/* ── Stats cards ── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px,1fr)); gap: 14px; margin-bottom: 28px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 16px; text-align: center; }
.stat-value { font-size: 28px; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ── Admin tabs ── */
.admin-tabs { display: flex; gap: 2px; background: var(--border); border-radius: 8px; padding: 3px; margin-bottom: 24px; width: fit-content; }
.tab-btn { padding: 7px 18px; border-radius: 6px; border: none; cursor: pointer; font-size: 14px; font-weight: 500; background: transparent; color: var(--text-muted); transition: background .15s, color .15s; }
.tab-btn.active { background: var(--surface); color: var(--primary); box-shadow: 0 1px 4px rgba(0,0,0,.1); }

/* ── Toast ── */
.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 400; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { background: #323130; color: #fff; padding: 12px 18px; border-radius: 6px; font-size: 14px; box-shadow: 0 4px 16px rgba(0,0,0,.25); pointer-events: auto; display: flex; align-items: center; gap: 10px; animation: slideIn .2s ease; min-width: 240px; max-width: 360px; }
.toast.success { background: var(--success); }
.toast.error   { background: var(--danger); }
.toast.warning { background: var(--warning); }
@keyframes slideIn { from { transform: translateY(16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ── Calendar source cards ── */
.source-card { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 10px; overflow: hidden; }
.source-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; gap: 12px; flex-wrap: wrap; }
.source-header:hover { background: var(--bg); }
.calendar-picker { padding: 0 16px 14px; border-top: 1px solid var(--border); background: var(--bg); }

/* ── Empty states ── */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state h3 { font-size: 16px; color: var(--text); margin-bottom: 6px; }
.empty-state p { font-size: 13px; }
.loading { text-align: center; padding: 40px; color: var(--text-muted); }

/* ── Misc ── */
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.back-link { display: inline-flex; align-items: center; gap: 6px; color: var(--text-muted); font-size: 13px; margin-bottom: 16px; }
.back-link:hover { color: var(--primary); }

@media (max-width: 600px) {
  .form-row { grid-template-columns: 1fr; }
  .photo-grid { columns: 2 120px; }
  .folders-grid { grid-template-columns: 1fr; }
}
