/* ============================================================
   styles.css — 案內所 共用樣式
   All common CSS shared across dashboard, invoice, contract,
   accounting, clients, settings, calculator, calendar pages.
   Requires design-tokens.css to be loaded BEFORE this file.
   ============================================================ */

/* ── FONT ── */
/* Google Fonts loaded via <link> in each HTML page (parallel, non-blocking).
   The @import that was here has been removed to avoid a duplicate blocking request. */

/* ── CSS VARIABLES ── */
/* All variables now defined in design-tokens.css.
   Legacy aliases (--bg, --bg-card, --border, etc.) are preserved there
   for backward compatibility with page-level inline styles. */

/* ── RESET ── */
* { box-sizing: border-box; margin: 0; padding: 0; }

/* ── BODY ── */
body {
  font-family: var(--font-body);
  background: var(--color-bg-primary);
  color: var(--color-text-primary);
  -webkit-font-smoothing: antialiased;
  transition: background .3s, color .3s;
}

/* ── APP LAYOUT ── */
.app { display: flex; min-height: 100vh; }

/* ── SIDEBAR (Glass Vibrancy) ── */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-right: 0.5px solid var(--color-border);
  box-shadow: 1px 0 8px rgba(0,0,0,0.03);
  display: flex; flex-direction: column;
  padding: 0;
  z-index: 100;
  transition: transform var(--duration-normal) var(--ease-smooth), background .3s;
}

.sidebar-logo {
  padding: 20px 20px 16px;
  display: flex; align-items: center; gap: 8px;
  border-bottom: 0.5px solid var(--border);
  text-decoration: none;
}
.sidebar-logo img { height: 32px; width: 32px; object-fit: contain; }
.sidebar-logo-text {
  font-family: 'Noto Serif TC', serif;
  font-size: 18px; font-weight: 700;
  color: var(--text-primary); letter-spacing: 0.08em;
}
.sidebar-logo-text span { color: var(--orange); }

.sidebar-nav { flex: 1; padding: 16px 12px; overflow-y: auto; }

.nav-section-label {
  font-size: 10px; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--text-muted);
  padding: 0 8px; margin: 16px 0 6px;
}

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: var(--radius-sm);
  font-size: var(--text-sm); color: var(--color-text-secondary);
  cursor: pointer; transition: all var(--duration-fast) var(--ease-smooth);
  margin-bottom: 2px; text-decoration: none;
  user-select: none;
}
.nav-item:hover { background: rgba(0,0,0,0.04); color: var(--color-text-primary); }
.nav-item.active {
  background: rgba(0,0,0,0.06);
  color: var(--color-text-primary); font-weight: 500;
  box-shadow: inset 3px 0 0 var(--color-accent);
}

.nav-icon { font-size: 16px; flex-shrink: 0; width: 20px; text-align: center; }

.nav-badge {
  margin-left: auto; font-size: 11px;
  background: var(--orange); color: #fff;
  border-radius: 10px; padding: 1px 7px;
  font-weight: 500;
}

.sidebar-bottom {
  padding: 16px 12px;
  border-top: 0.5px solid var(--border);
}

/* ── USER CARD (sidebar bottom) ── */
.user-card {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px;
  transition: background .15s;
}
.user-card:hover { background: var(--bg); }

.user-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--orange-light);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 500; color: var(--orange-dark);
  flex-shrink: 0;
}

.user-info { flex: 1; min-width: 0; }
.user-name {
  font-size: 13px; font-weight: 500; color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-plan { font-size: 11px; color: var(--orange); }

/* ── MAIN CONTAINER ── */
.main {
  flex: 1; margin-left: var(--sidebar-w);
  display: flex; flex-direction: column;
  min-height: 100vh;
}

/* ── TOPBAR (Glass Vibrancy) ── */
.topbar {
  position: sticky; top: 0;
  height: 56px; display: flex; align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-6);
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-bottom: 0.5px solid var(--color-border);
  box-shadow: 0 1px 4px rgba(0,0,0,0.03);
  z-index: 90;
  transition: background .3s;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-title { font-size: 15px; font-weight: 500; color: var(--text-primary); white-space: nowrap; flex-shrink: 0; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

/* ── THEME TOGGLE BUTTON ── */
.theme-btn {
  width: 34px; height: 34px; border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: var(--bg); color: var(--text-primary);
  cursor: pointer;
  font-size: 16px; display: flex; align-items: center; justify-content: center;
  transition: all .2s;
}
.theme-btn:hover { transform: scale(1.1); }

/* ── BUTTONS (Premium) ── */
.btn-primary {
  display: flex; align-items: center; gap: 6px;
  padding: 9px 18px; border-radius: var(--radius-sm);
  background: var(--color-accent-gradient);
  color: #fff; border: none;
  font-size: var(--text-sm); font-weight: 500;
  font-family: var(--font-body);
  letter-spacing: 0.01em;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0,0,0,0.15), 0 4px 8px -2px rgba(224,110,0,0.3), inset 0 1px 0 rgba(255,255,255,0.2);
  transition: all var(--duration-fast) var(--ease-smooth);
}
.btn-primary:hover {
  filter: brightness(1.05);
  box-shadow: 0 2px 4px rgba(0,0,0,0.18), 0 6px 12px -2px rgba(224,110,0,0.35), inset 0 1px 0 rgba(255,255,255,0.25);
}
.btn-primary:active {
  filter: brightness(0.95);
  transform: scale(0.98);
  box-shadow: 0 1px 1px rgba(0,0,0,0.15), inset 0 1px 3px rgba(0,0,0,0.1);
}

.btn-outline {
  padding: 9px 18px; border-radius: var(--radius-sm);
  background: rgba(0,0,0,0.04);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  border: 0.5px solid var(--color-border-strong);
  color: var(--color-text-primary);
  font-size: var(--text-sm); font-weight: 500;
  font-family: var(--font-body);
  cursor: pointer;
  box-shadow: var(--shadow-xs);
  transition: all var(--duration-fast) var(--ease-smooth);
}
.btn-outline:hover {
  background: rgba(0,0,0,0.06);
  box-shadow: var(--shadow-sm);
}
.btn-outline:active {
  background: rgba(0,0,0,0.08);
  transform: scale(0.98);
}

/* Ghost / Text button */
.btn-ghost {
  background: transparent; border: none;
  color: var(--color-accent);
  font-weight: 500; font-size: var(--text-sm);
  font-family: var(--font-body);
  cursor: pointer; padding: 9px 18px;
  border-radius: var(--radius-sm);
  transition: background var(--duration-fast) var(--ease-smooth);
}
.btn-ghost:hover { background: rgba(240,122,0,0.06); }

.topbar-quick-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: 8px;
  background: var(--orange); color: #fff;
  border: none; font-size: 13px; font-weight: 500;
  font-family: 'Noto Sans TC', sans-serif;
  cursor: pointer; transition: opacity .2s;
}
.topbar-quick-btn:hover { opacity: .88; }

/* ── MOBILE SIDEBAR TOGGLE ── */
.mobile-menu-btn {
  display: none; background: none; border: none;
  font-size: 20px; cursor: pointer; color: var(--text-primary);
}
.sidebar-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.4); z-index: 49;
}

/* ── CONTENT AREA ── */
.content { padding: 24px 28px; flex: 1; }

/* ── NOTIFICATION BUTTON & DROPDOWN ── */
.notif-btn {
  position: relative; width: 34px; height: 34px; border-radius: 50%;
  border: 1px solid var(--border-strong); background: var(--bg);
  color: var(--text-primary);
  cursor: pointer; font-size: 16px; display: flex;
  align-items: center; justify-content: center; transition: all .2s;
}
.notif-btn:hover { border-color: var(--orange); }
.notif-dot {
  position: absolute; top: 4px; right: 4px; width: 8px; height: 8px;
  border-radius: 50%; background: var(--orange); border: 1.5px solid var(--bg-card);
}
.notif-dropdown {
  position: fixed; top: 60px; right: 16px; width: 320px;
  background: var(--bg-card); border: 0.5px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: 0 8px 32px rgba(0,0,0,.15);
  z-index: 200; overflow: hidden; animation: fadeUp .2s ease both;
}
.notif-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; border-bottom: 0.5px solid var(--border);
  font-size: 14px; font-weight: 500; color: var(--text-primary);
}
.notif-item {
  display: flex; gap: 10px; padding: 12px 16px;
  border-bottom: 0.5px solid var(--border); cursor: pointer;
  transition: background .15s;
}
.notif-item:hover { background: var(--bg); }
.notif-item.unread { background: rgba(240,122,0,0.04); }
.notif-item-icon { font-size: 18px; flex-shrink: 0; }
.notif-item-body { flex: 1; }
.notif-item-title { font-size: 13px; font-weight: 500; color: var(--text-primary); margin-bottom: 2px; }
.notif-item-time { font-size: 11px; color: var(--text-muted); }
.notif-empty {
  padding: 32px 16px; text-align: center;
  color: var(--text-muted); font-size: 13px;
}

/* ── GLOBAL SEARCH ── */
.search-trigger {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 14px; border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--bg); cursor: pointer;
  font-size: 13px; color: var(--text-muted);
  transition: all .2s; min-width: 200px;
  font-family: 'Noto Sans TC', sans-serif;
}
.search-trigger:hover { border-color: var(--orange); color: var(--text-primary); }
.search-trigger-icon { font-size: 14px; flex-shrink: 0; }
.search-trigger-text { flex: 1; text-align: left; }
.search-trigger-kbd {
  font-size: 10px; padding: 2px 5px;
  border-radius: 4px; background: var(--bg-input,var(--bg));
  border: 0.5px solid var(--border); color: var(--text-muted);
  font-family: monospace; flex-shrink: 0;
}

.search-overlay {
  display: none; position: fixed; inset: 0; z-index: 500;
  background: rgba(0,0,0,0.5); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
  align-items: flex-start; justify-content: center;
  padding-top: 80px;
}
.search-overlay.open { display: flex; }

.search-modal {
  width: 100%; max-width: 600px; margin: 0 16px;
  background: var(--bg-card); border-radius: 16px;
  border: 0.5px solid var(--border);
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  overflow: hidden;
  animation: searchIn .15s ease both;
}

.search-input-row {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px; border-bottom: 0.5px solid var(--border);
}
.search-input-icon { font-size: 17px; color: var(--text-muted); flex-shrink: 0; }
.search-input-field {
  flex: 1; border: none; outline: none; font-size: 16px;
  font-family: 'Noto Sans TC', sans-serif;
  color: var(--text-primary); background: transparent;
}
.search-input-field::placeholder { color: var(--text-muted); }
.search-esc {
  font-size: 11px; padding: 2px 7px; border-radius: 4px;
  background: var(--bg); border: 0.5px solid var(--border);
  color: var(--text-muted); font-family: monospace; flex-shrink: 0;
}

.search-results { max-height: 440px; overflow-y: auto; }

.search-section-label {
  padding: 10px 18px 6px;
  font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--text-muted); font-weight: 500;
}

.search-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 18px; cursor: pointer;
  transition: background .1s;
  border-radius: 0;
}
.search-item:hover, .search-item.active {
  background: var(--nav-active-bg, #FFF3E0);
}
.search-item-icon {
  width: 34px; height: 34px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; flex-shrink: 0;
  background: var(--bg);
}
.search-item-body { flex: 1; min-width: 0; }
.search-item-title {
  font-size: 13px; font-weight: 500;
  color: var(--text-primary); margin-bottom: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.search-item-title mark {
  background: rgba(240,122,0,0.2); color: var(--orange);
  border-radius: 2px; padding: 0 1px;
}
.search-item-sub { font-size: 12px; color: var(--text-muted); }
.search-item-badge {
  font-size: 11px; padding: 2px 8px; border-radius: 10px;
  flex-shrink: 0; font-weight: 500;
}

.search-empty {
  padding: 40px 20px; text-align: center;
  color: var(--text-muted); font-size: 14px;
}
.search-empty-icon { font-size: 32px; margin-bottom: 10px; }

.search-footer {
  padding: 10px 18px; border-top: 0.5px solid var(--border);
  display: flex; gap: 16px; align-items: center;
  font-size: 11px; color: var(--text-muted);
}
.search-footer-item { display: flex; align-items: center; gap: 4px; }
.search-footer-kbd {
  font-size: 10px; padding: 1px 5px; border-radius: 3px;
  background: var(--bg); border: 0.5px solid var(--border);
  font-family: monospace;
}

/* ── VIEW TABS (shared by invoice, contract, accounting, calculator) ── */
.view-tabs {
  display: flex; gap: 0;
  background: var(--bg-card);
  border: 0.5px solid var(--border);
  border-radius: 10px; padding: 4px;
  width: fit-content; margin-bottom: 20px;
}
.view-tab {
  padding: 7px 16px; border-radius: 7px;
  font-size: 13px; cursor: pointer; border: none;
  background: transparent; color: var(--text-muted);
  font-family: 'Noto Sans TC', sans-serif; transition: all .2s;
}
.view-tab.active { background: var(--orange); color: #fff; font-weight: 500; }

/* ── MODAL SCROLL LOCK ── */
body.modal-open {
  overflow: hidden;
}

/* ── TOAST (Premium Glass) ── */
.toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 9999;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 0.5px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  color: var(--color-text-primary);
  padding: 14px 18px 14px 22px;
  font-size: var(--text-sm);
  max-width: 380px;
  transform: translateY(60px); opacity: 0;
  transition: all var(--duration-normal) var(--ease-spring);
  pointer-events: none;
  overflow: hidden;
}
.toast::before {
  content: "";
  position: absolute;
  left: 0; top: 0;
  width: 3px; height: 100%;
  border-radius: 2px 0 0 2px;
  background: var(--color-accent);
}
.toast.show { transform: translateY(0); opacity: 1; pointer-events: auto; }
.toast.toast-success::before { background: var(--color-success); }
.toast.toast-error::before   { background: var(--color-error); }
.toast.toast-warning::before { background: var(--color-warning); }

/* ── FOCUS-VISIBLE (accessibility) ── */
:focus-visible {
  outline: 2px solid var(--orange);
  outline-offset: 2px;
}

.search-input-field:focus-visible {
  outline: none;
}

/* ── KEYFRAMES ── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes searchIn {
  from { opacity: 0; transform: translateY(-12px) scale(.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* === Micro-interaction Keyframes === */
@keyframes stagger-in {
  0% { opacity: 0; transform: translateY(8px); }
  100% { opacity: 1; transform: translateY(0); }
}

@keyframes modal-spring {
  0% { opacity: 0; transform: scale(0.92) translateY(16px); }
  60% { transform: scale(1.01) translateY(-2px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes toast-progress {
  0% { width: 100%; }
  100% { width: 0%; }
}

@keyframes page-fade {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

/* === Skeleton Loading === */
.skeleton {
  background: linear-gradient(90deg, var(--color-bg-tertiary) 25%, rgba(0,0,0,0.04) 50%, var(--color-bg-tertiary) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius-sm);
}

@keyframes skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-text { height: 14px; margin-bottom: 8px; }
.skeleton-title { height: 20px; width: 60%; margin-bottom: 12px; }
.skeleton-card { height: 120px; border-radius: var(--radius-md); }
.skeleton-avatar { width: 32px; height: 32px; border-radius: var(--radius-full); }

/* === Card Premium Utilities === */
.premium-card {
  position: relative;
  overflow: hidden;
}
.premium-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.6), transparent);
  z-index: 1;
}

/* === Page Fade-in === */
.main-content {
  animation: page-fade 0.2s var(--ease-smooth);
}

/* === Dark Mode Component Overrides === */
[data-theme="dark"] .sidebar {
  box-shadow: 1px 0 12px rgba(0,0,0,0.15);
}

[data-theme="dark"] .topbar {
  box-shadow: 0 1px 6px rgba(0,0,0,0.15);
}

[data-theme="dark"] .nav-item:hover {
  background: rgba(255,255,255,0.04);
}

[data-theme="dark"] .nav-item.active {
  background: rgba(255,255,255,0.06);
}

[data-theme="dark"] .premium-card::before {
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.08), transparent);
}

[data-theme="dark"] .btn-outline {
  background: rgba(255,255,255,0.06);
  border-color: var(--color-border-strong);
}

[data-theme="dark"] .skeleton {
  background: linear-gradient(90deg, var(--color-bg-tertiary) 25%, rgba(255,255,255,0.04) 50%, var(--color-bg-tertiary) 75%);
  background-size: 200% 100%;
}

/* === Reduced Motion === */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── RESPONSIVE: MOBILE SIDEBAR ── */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform .3s, background .3s;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }
  .main { margin-left: 0; }
  .mobile-menu-btn { display: block; }
  .content { padding: 16px; }
  .topbar { padding: 0 16px; height: auto; min-height: 56px; flex-wrap: wrap; gap: 8px; padding-top: 8px; padding-bottom: 8px; }
  .topbar-left { flex-shrink: 0; }
  .topbar-right { gap: 6px; flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .topbar-right .btn-outline,
  .topbar-right .btn-primary { white-space: nowrap; font-size: 12px; padding: 6px 10px; flex-shrink: 0; }
  .topbar-right .notif-btn,
  .topbar-right .theme-btn { flex-shrink: 0; }
  .topbar-right span { white-space: nowrap; flex-shrink: 0; font-size: 11px; }

  /* Search trigger compact on mobile */
  .search-trigger-text { display: none; }
  .search-trigger-kbd { display: none; }
  .search-trigger { min-width: 36px; padding: 7px 10px; justify-content: center; }
  .search-overlay { padding-top: 20px; align-items: flex-start; }
}

/* ── EMPTY STATE (shared) ── */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}
.empty-state-icon {
  font-size: 40px;
  margin-bottom: 12px;
}
.empty-state-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}
.empty-state-desc {
  font-size: 13px;
  margin-bottom: 20px;
  line-height: 1.5;
}
.empty-state .btn-primary {
  font-size: 13px;
  padding: 8px 20px;
}

/* ── RESPONSIVE: EXTRA-SMALL TOPBAR ── */
@media (max-width: 480px) {
  .topbar-right .btn-outline,
  .topbar-right .btn-primary { font-size: 11px; padding: 5px 8px; }
  .topbar-title { font-size: 13px; }
}
