/* ============================================================
   DentFlow Global Stylesheet — Apple-inspired Design System
   ============================================================ */

/* Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ── Design Tokens ─────────────────────────────────────────── */
:root {
  --color-bg:             #F5F5F7;
  --color-bg-dark:        #1D1D1F;
  --color-surface:        #FFFFFF;
  --color-surface-2:      #F9F9F9;
  --color-surface-dark:   #2C2C2E;

  --color-text-primary:   #1D1D1F;
  --color-text-secondary: #6E6E73;
  --color-text-inverse:   #F5F5F7;

  --color-primary:        #0071E3;
  --color-primary-hover:  #0077ED;
  --color-primary-light:  rgba(0, 113, 227, 0.10);

  --color-success:  #34C759;
  --color-warning:  #FF9F0A;
  --color-danger:   #FF3B30;
  --color-info:     #0071E3;

  --color-border:        rgba(0, 0, 0, 0.08);
  --color-border-strong: rgba(0, 0, 0, 0.15);

  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'SF Pro Display',
                 'Helvetica Neue', 'Noto Sans TC', Arial, sans-serif;

  --font-size-hero: clamp(36px, 5vw, 64px);
  --font-size-h1:   clamp(26px, 3vw, 44px);
  --font-size-h2:   clamp(20px, 2.5vw, 30px);
  --font-size-h3:   20px;
  --font-size-body: 17px;
  --font-size-sm:   14px;
  --font-size-xs:   12px;

  --font-weight-bold: 700;
  --font-weight-semi: 600;
  --font-weight-reg:  400;

  --line-height-tight: 1.2;
  --line-height-base:  1.6;

  --space-xs:  4px;
  --space-sm:  8px;
  --space-md:  16px;
  --space-lg:  24px;
  --space-xl:  40px;
  --space-2xl: 64px;
  --space-3xl: 96px;

  --radius-sm:   6px;
  --radius-md:   12px;
  --radius-lg:   18px;
  --radius-xl:   24px;
  --radius-full: 980px;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);

  --sidebar-width: 240px;
  --navbar-height: 52px;

  --transition: all 200ms cubic-bezier(0.42, 0, 0.58, 1);
}

/* ── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font-family);
  font-size: var(--font-size-body);
  color: var(--color-text-primary);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  line-height: var(--line-height-base);
}
a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img, svg { display: block; }
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; }

/* ── Navbar (Glassmorphism) ────────────────────────────────── */
.navbar {
  position: sticky;
  top: 0;
  z-index: 200;
  height: var(--navbar-height);
  background: rgba(255, 255, 255, 0.80);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-xl);
}
.navbar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-weight: var(--font-weight-bold);
  font-size: 18px;
  color: var(--color-text-primary);
  text-decoration: none;
}
.navbar-brand .logo-icon {
  width: 28px;
  height: 28px;
  background: var(--color-primary);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
}
.navbar-actions { display: flex; align-items: center; gap: var(--space-md); }
.navbar-user {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  padding: 6px 12px;
  border-radius: var(--radius-full);
  transition: var(--transition);
  cursor: pointer;
}
.navbar-user:hover { background: rgba(0,0,0,0.04); }
.user-avatar {
  width: 30px;
  height: 30px;
  background: var(--color-primary-light);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-primary);
}

/* ── Admin Shell Layout ────────────────────────────────────── */
.admin-shell {
  display: flex;
  min-height: calc(100vh - var(--navbar-height));
}

/* ── Sidebar ───────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  padding: var(--space-lg) 0;
  position: sticky;
  top: var(--navbar-height);
  height: calc(100vh - var(--navbar-height));
  overflow-y: auto;
  flex-shrink: 0;
}
.sidebar-section-title {
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semi);
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: var(--space-sm) var(--space-lg);
  margin-top: var(--space-md);
}
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px var(--space-lg);
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--color-text-secondary);
  text-decoration: none;
  border-radius: 0;
  transition: var(--transition);
  margin: 1px var(--space-sm);
  border-radius: var(--radius-sm);
}
.sidebar-link:hover { background: rgba(0,0,0,0.04); color: var(--color-text-primary); text-decoration: none; }
.sidebar-link.active {
  background: var(--color-primary-light);
  color: var(--color-primary);
  font-weight: var(--font-weight-semi);
}
.sidebar-link .icon { font-size: 16px; width: 20px; text-align: center; }

/* ── Main Content ──────────────────────────────────────────── */
.main-content {
  flex: 1;
  padding: var(--space-2xl) var(--space-xl);
  min-width: 0;
}
.page-header {
  margin-bottom: var(--space-xl);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-md);
}
.page-title {
  font-size: var(--font-size-h2);
  font-weight: var(--font-weight-bold);
  line-height: var(--line-height-tight);
  color: var(--color-text-primary);
}
.page-subtitle {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  margin-top: var(--space-xs);
}

/* ── Stats Grid ────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--space-lg);
  margin-bottom: var(--space-xl);
}
.stat-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}
.stat-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.stat-label {
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semi);
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: var(--space-sm);
}
.stat-value {
  font-size: clamp(28px, 3vw, 40px);
  font-weight: var(--font-weight-bold);
  color: var(--color-text-primary);
  line-height: 1;
}
.stat-change {
  font-size: var(--font-size-xs);
  margin-top: var(--space-xs);
  color: var(--color-text-secondary);
}
.stat-change.up { color: var(--color-success); }
.stat-change.down { color: var(--color-danger); }
.stat-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  margin-bottom: var(--space-md);
}
.stat-icon.blue { background: rgba(0,113,227,0.10); }
.stat-icon.green { background: rgba(52,199,89,0.12); }
.stat-icon.orange { background: rgba(255,159,10,0.12); }
.stat-icon.red { background: rgba(255,59,48,0.12); }

/* ── Card ──────────────────────────────────────────────────── */
.card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.card-header {
  padding: var(--space-lg);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-title {
  font-size: var(--font-size-h3);
  font-weight: var(--font-weight-semi);
}
.card-body { padding: var(--space-lg); }

/* ── Table ─────────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: var(--font-size-sm); }
thead th {
  background: var(--color-bg);
  padding: 10px var(--space-md);
  text-align: left;
  font-weight: var(--font-weight-semi);
  color: var(--color-text-secondary);
  font-size: var(--font-size-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}
tbody td {
  padding: var(--space-md);
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text-primary);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(0,0,0,0.015); }

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 10px 20px;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semi);
  border: none;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  white-space: nowrap;
}
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-hover); transform: scale(1.02); color: #fff; text-decoration: none; }
.btn-secondary { background: transparent; color: var(--color-primary); border: 1.5px solid var(--color-primary); }
.btn-secondary:hover { background: var(--color-primary-light); text-decoration: none; }
.btn-danger { background: transparent; color: var(--color-danger); border: 1.5px solid var(--color-danger); }
.btn-danger:hover { background: rgba(255,59,48,0.08); text-decoration: none; }
.btn-sm { padding: 6px 14px; font-size: var(--font-size-xs); }
.btn-icon { padding: 8px; border-radius: 50%; width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center; }

/* ── Badge / Status ────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semi);
}
.badge-success { background: rgba(52,199,89,0.12); color: #1a7a35; }
.badge-warning { background: rgba(255,159,10,0.12); color: #a06600; }
.badge-danger  { background: rgba(255,59,48,0.12);  color: #c0001a; }
.badge-info    { background: var(--color-primary-light); color: var(--color-primary); }
.badge-default { background: rgba(0,0,0,0.06); color: var(--color-text-secondary); }

/* ── Form ──────────────────────────────────────────────────── */
.form-group { margin-bottom: var(--space-lg); }
.form-label {
  display: block;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semi);
  color: var(--color-text-secondary);
  margin-bottom: 6px;
}
.form-control {
  width: 100%;
  padding: 12px 16px;
  font-size: var(--font-size-body);
  color: var(--color-text-primary);
  background: var(--color-surface);
  border: 1.5px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  transition: var(--transition);
  outline: none;
  appearance: none;
}
.form-control:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(0,113,227,0.15);
}
.form-control::placeholder { color: var(--color-text-secondary); opacity: 0.6; }

/* ── Login Page ────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
  padding: var(--space-xl);
}
.login-card {
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  padding: var(--space-2xl);
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--color-border);
}
.login-logo {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-2xl);
  justify-content: center;
}
.login-logo-icon {
  width: 44px;
  height: 44px;
  background: var(--color-primary);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 22px;
  font-weight: 700;
}
.login-logo-text {
  font-size: 22px;
  font-weight: var(--font-weight-bold);
  color: var(--color-text-primary);
}
.login-heading {
  font-size: var(--font-size-h3);
  font-weight: var(--font-weight-bold);
  margin-bottom: var(--space-xs);
}
.login-sub {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  margin-bottom: var(--space-xl);
}
.login-btn {
  width: 100%;
  padding: 14px;
  font-size: var(--font-size-body);
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-full);
  font-weight: var(--font-weight-semi);
  cursor: pointer;
  transition: var(--transition);
}
.login-btn:hover:not(:disabled) { background: var(--color-primary-hover); transform: scale(1.01); }
.login-btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }
.error-msg {
  background: rgba(255,59,48,0.08);
  border: 1px solid rgba(255,59,48,0.2);
  color: var(--color-danger);
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-md);
  font-size: var(--font-size-sm);
  margin-bottom: var(--space-md);
  display: none;
}
.error-msg.show { display: block; }

/* ── Fade In Animation ─────────────────────────────────────── */
.fade-in {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 500ms ease, transform 500ms ease;
}
.fade-in.visible { opacity: 1; transform: translateY(0); }

/* ── Loading Spinner ───────────────────────────────────────── */
.spinner {
  width: 18px;
  height: 18px;
  border: 2.5px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Empty State ───────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: var(--space-3xl) var(--space-xl);
  color: var(--color-text-secondary);
}
.empty-state-icon { font-size: 40px; margin-bottom: var(--space-md); }
.empty-state-text { font-size: var(--font-size-body); }

/* ── Mobile Nav Components ──────────────────────────────────── */
.hamburger-btn {
  display: none;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  margin-right: var(--space-sm);
  cursor: pointer;
  color: var(--color-text-primary);
  -webkit-tap-highlight-color: transparent;
  transition: background 150ms;
  flex-shrink: 0;
  order: -1;
}
.hamburger-btn:hover { background: rgba(0,0,0,0.05); }
.hamburger-icon { font-size: 20px; line-height: 1; pointer-events: none; }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  top: var(--navbar-height);
  background: rgba(0, 0, 0, 0.45);
  z-index: 140;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  animation: overlayFadeIn 200ms ease;
}
.sidebar-overlay.show { display: block; }
@keyframes overlayFadeIn {
  from { opacity: 0; } to { opacity: 1; }
}

/* ── Responsive ────────────────────────────────────────────── */

/* ── Tablet & Mobile (≤ 768px) ─────────────────────────────── */
@media (max-width: 768px) {

  /* Hamburger: show */
  .hamburger-btn { display: flex; }

  /* Sidebar: slide-in drawer */
  .sidebar {
    display: flex;
    flex-direction: column;
    position: fixed;
    top: var(--navbar-height);
    left: 0;
    height: calc(100vh - var(--navbar-height));
    width: min(var(--sidebar-width), 80vw);
    transform: translateX(-110%);
    transition: transform 280ms cubic-bezier(0.4, 0, 0.2, 1), box-shadow 280ms;
    z-index: 150;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    box-shadow: none;
  }
  .sidebar.is-open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }

  /* Layout */
  .navbar { padding: 0 var(--space-md); }
  .main-content {
    padding: var(--space-lg) var(--space-md);
    padding-bottom: calc(var(--space-xl) + env(safe-area-inset-bottom, 0px));
  }
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: var(--space-md); }

  /* Page header: stack vertically */
  .page-header { flex-direction: column; align-items: flex-start; }

  /* Table: smooth iOS scroll + shadow hint */
  .table-wrapper {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    background-image:
      linear-gradient(to right, var(--color-surface) 10%, transparent),
      linear-gradient(to left,  var(--color-surface) 10%, transparent),
      radial-gradient(ellipse at 0 50%, rgba(0,0,0,.08) 0, transparent 70%),
      radial-gradient(ellipse at 100% 50%, rgba(0,0,0,.08) 0, transparent 70%);
    background-position: left, right, left, right;
    background-size: 32px 100%, 32px 100%, 16px 100%, 16px 100%;
    background-repeat: no-repeat;
    background-attachment: local, local, scroll, scroll;
  }

  /* Touch-friendly buttons (Apple HIG: ≥ 44pt) */
  .btn-sm { min-height: 36px; padding: 8px 14px; }

  /* Navbar: hide username text, keep avatar */
  #navbar-user-name { display: none; }

  /* Modal */
  .modal-box { width: 96%; }
  .modal-overlay { overscroll-behavior: contain; }
}

/* ── Mobile only (≤ 480px) ─────────────────────────────────── */
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .login-card { padding: var(--space-xl); }
  .navbar-user small { display: none; }
  #navbar-user-name  { display: none; }
  .clinic-switcher-name { max-width: 100px; }
  .login-page {
    padding-bottom: calc(var(--space-xl) + env(safe-area-inset-bottom, 0px));
  }
}

/* ── Clinic Switcher (Doctor cross-clinic) ─────────────────── */
.clinic-switcher {
  position: relative;
}
.clinic-switcher-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  background: var(--color-primary-light);
  border: 1.5px solid rgba(0,113,227,0.2);
  border-radius: var(--radius-full);
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--color-primary);
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}
.clinic-switcher-btn:hover {
  background: rgba(0,113,227,0.16);
}
.clinic-switcher-name {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.clinic-switcher-arrow {
  font-size: 10px;
  opacity: 0.7;
}
.clinic-switcher-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  min-width: 200px;
  z-index: 300;
  overflow: hidden;
  animation: fadeDropdown 150ms ease;
}
@keyframes fadeDropdown {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.clinic-switcher-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  width: 100%;
  padding: 10px var(--space-md);
  background: none;
  border: none;
  font-size: var(--font-size-sm);
  color: var(--color-text-primary);
  cursor: pointer;
  text-align: left;
  transition: background 150ms;
}
.clinic-switcher-item:hover:not(:disabled) {
  background: var(--color-primary-light);
}
.clinic-switcher-item.is-current {
  color: var(--color-primary);
  font-weight: 600;
  cursor: default;
}
.clinic-switcher-item small {
  margin-left: auto;
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
}
.clinic-switcher-item-icon {
  width: 18px;
  text-align: center;
  flex-shrink: 0;
}

/* ── Font size md/lg tokens (used in login clinic selection) ── */
:root {
  --font-size-md: 15px;
  --font-size-lg: 18px;
}
