/* ================================================================
   EMS.tw — Shared Design System
   Dark Mode OLED × Medical Teal
   Import this file in every page: <link rel="stylesheet" href="/shared.css">
   Adjust relative path as needed (e.g. ../shared.css)
================================================================ */

/* ── Google Fonts ── */
@import url('https://fonts.googleapis.com/css2?family=Figtree:wght@300;400;500;600;700;800&family=Noto+Sans+TC:wght@300;400;500;700&display=swap');

/* ── Design Tokens ── */
:root {
    --bg-base:      #070B14;
    --bg-surface:   #0D1525;
    --bg-elevated:  #152035;
    --bg-hover:     #1A2B44;
    --border:       rgba(255,255,255,0.07);
    --border-md:    rgba(255,255,255,0.12);
    --border-active:rgba(6,182,212,0.45);
    --text-primary:   #F0F4FF;
    --text-secondary: #8899B4;
    --text-muted:     #4E6080;
    --cyan:       #06B6D4;
    --cyan-light: #22D3EE;
    --cyan-dim:   rgba(6,182,212,0.15);
    --cyan-glow:  rgba(6,182,212,0.25);
    --green:      #10B981;
    --green-dim:  rgba(16,185,129,0.15);
    --red:        #EF4444;
    --red-dim:    rgba(239,68,68,0.15);
    --amber:      #F59E0B;
    --amber-dim:  rgba(245,158,11,0.15);
    --purple:     #8B5CF6;
    --r-sm: 8px; --r-md: 12px; --r-lg: 16px; --r-xl: 20px; --r-2xl: 24px;
    --shadow-md: 0 4px 16px rgba(0,0,0,.5);
    --shadow-lg: 0 8px 32px rgba(0,0,0,.6);
    --t-fast: 150ms ease; --t-base: 200ms ease;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
    font-family: 'Figtree', 'Noto Sans TC', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-base);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ── Shared Header ── */
.site-header {
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    padding: 14px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 100;
}
.site-header-icon {
    width: 36px; height: 36px;
    background: var(--cyan-dim);
    border: 1px solid var(--border-active);
    border-radius: var(--r-sm);
    display: flex; align-items: center; justify-content: center;
    color: var(--cyan);
    flex-shrink: 0;
}
.site-header-icon svg { width: 18px; height: 18px; }
.site-header h1 { font-size: 1rem; font-weight: 700; color: var(--text-primary); }
.site-header p  { font-size: .72rem; color: var(--text-muted); }

.back-link {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: .8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-decoration: none;
    padding: 6px 12px;
    border-radius: var(--r-sm);
    border: 1px solid var(--border-md);
    transition: color var(--t-fast), border-color var(--t-fast), background var(--t-fast);
}
.back-link:hover { color: var(--cyan); border-color: var(--border-active); background: var(--cyan-dim); }
.back-link svg { width: 14px; height: 14px; }

/* ── Cards ── */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--r-xl);
    padding: 20px;
}
.card-accent-cyan  { border-left: 3px solid var(--cyan); }
.card-accent-green { border-left: 3px solid var(--green); }
.card-accent-red   { border-left: 3px solid var(--red); }
.card-accent-amber { border-left: 3px solid var(--amber); }

/* ── Buttons ── */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    border: none; border-radius: var(--r-md); padding: 11px 20px;
    font-size: .9rem; font-weight: 700; font-family: inherit;
    cursor: pointer; text-decoration: none;
    transition: background var(--t-fast), box-shadow var(--t-fast), transform var(--t-fast);
    -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.97); }
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }

.btn-primary { background: var(--cyan); color: #030712; }
.btn-primary:hover { background: var(--cyan-light); box-shadow: 0 0 20px var(--cyan-glow); }

.btn-success { background: var(--green); color: #030712; }
.btn-success:hover { box-shadow: 0 0 16px rgba(16,185,129,.35); }

.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { box-shadow: 0 0 16px rgba(239,68,68,.35); }

.btn-ghost {
    background: transparent; color: var(--text-secondary);
    border: 1px solid var(--border-md);
}
.btn-ghost:hover { color: var(--text-primary); border-color: var(--border-active); background: var(--bg-elevated); }

.btn:disabled, .btn[disabled] {
    opacity: .4; cursor: not-allowed; pointer-events: none;
}

.btn-lg { padding: 14px 28px; font-size: 1rem; border-radius: var(--r-lg); }

/* ── Form Controls ── */
.form-label {
    display: block; font-size: .75rem; font-weight: 700;
    color: var(--text-muted); text-transform: uppercase;
    letter-spacing: .06em; margin-bottom: 6px;
}
.form-control {
    width: 100%;
    background: var(--bg-elevated);
    border: 1px solid var(--border-md);
    border-radius: var(--r-md);
    color: var(--text-primary);
    font-family: inherit;
    font-size: .9rem;
    padding: 10px 14px;
    transition: border-color var(--t-fast), box-shadow var(--t-fast);
    appearance: none; -webkit-appearance: none;
}
.form-control:focus {
    outline: none;
    border-color: var(--border-active);
    box-shadow: 0 0 0 3px var(--cyan-dim);
}
select.form-control {
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%238899B4' stroke-width='2' viewBox='0 0 24 24'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

/* ── Badges ── */
.badge {
    display: inline-flex; align-items: center;
    padding: 3px 10px; border-radius: var(--r-sm);
    font-size: .72rem; font-weight: 700; letter-spacing: .04em;
}
.badge-cyan   { background: var(--cyan-dim);  color: var(--cyan-light); border: 1px solid rgba(6,182,212,.2); }
.badge-green  { background: var(--green-dim); color: #6EE7B7; border: 1px solid rgba(16,185,129,.2); }
.badge-red    { background: var(--red-dim);   color: #FCA5A5; border: 1px solid rgba(239,68,68,.2); }
.badge-amber  { background: var(--amber-dim); color: #FDE68A; border: 1px solid rgba(245,158,11,.2); }
.badge-muted  { background: var(--bg-elevated); color: var(--text-secondary); border: 1px solid var(--border-md); }

/* ── Stats Grid ── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 12px;
}
.stat-box {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 14px 12px;
    text-align: center;
}
.stat-box-val {
    font-size: 1.8rem; font-weight: 800; color: var(--cyan-light);
    letter-spacing: -.02em; line-height: 1;
    font-variant-numeric: tabular-nums;
}
.stat-box-lbl {
    font-size: .7rem; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: .06em;
    margin-top: 4px; font-weight: 600;
}

/* ── Data Rows ── */
.data-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 9px 0; border-bottom: 1px solid var(--border);
    font-size: .86rem;
}
.data-row:last-child { border-bottom: none; }
.data-row-label { color: var(--text-secondary); }
.data-row-value { font-weight: 700; color: var(--text-primary); font-variant-numeric: tabular-nums; }
.data-row-value.good   { color: var(--green); }
.data-row-value.warn   { color: var(--amber); }
.data-row-value.danger { color: var(--red); }

/* ── Progress Bar ── */
.progress-track {
    height: 6px; background: var(--bg-elevated);
    border-radius: 3px; overflow: hidden;
}
.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--cyan), var(--cyan-light));
    border-radius: 3px;
    transition: width .4s ease;
    box-shadow: 0 0 8px var(--cyan-glow);
}

/* ── Page Layout ── */
.page-body {
    padding: 20px 16px 48px;
    max-width: 860px;
    margin: 0 auto;
    width: 100%;
}

/* ── Section Title ── */
.section-heading {
    font-size: .72rem; font-weight: 700;
    color: var(--text-muted); text-transform: uppercase;
    letter-spacing: .08em; margin-bottom: 12px;
}

/* ── Loading ── */
.loader-wrap {
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    min-height: 200px; gap: 14px;
    color: var(--text-secondary);
}
.spinner {
    width: 40px; height: 40px;
    border: 3px solid var(--border-md);
    border-top-color: var(--cyan);
    border-radius: 50%;
    animation: spin .75s linear infinite;
    box-shadow: 0 0 16px var(--cyan-glow);
}

/* ── Animations ── */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeUp {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
.fade-up { animation: fadeUp .25s ease; }

/* ── Alert ── */
.alert {
    padding: 12px 16px; border-radius: var(--r-md);
    font-size: .88rem; line-height: 1.5; margin: 12px 0;
}
.alert-danger  { background: var(--red-dim);   color: #FCA5A5; border: 1px solid rgba(239,68,68,.2); }
.alert-success { background: var(--green-dim); color: #6EE7B7; border: 1px solid rgba(16,185,129,.2); }
.alert-info    { background: var(--cyan-dim);  color: var(--cyan-light); border: 1px solid rgba(6,182,212,.2); }
.alert-warn    { background: var(--amber-dim); color: #FDE68A; border: 1px solid rgba(245,158,11,.2); }

/* ── Divider ── */
hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-base); }
::-webkit-scrollbar-thumb { background: var(--bg-elevated); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Prefers reduced motion ── */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ── RWD ── */
@media (min-width: 768px) {
    .page-body { padding: 28px 28px 60px; }
    .stats-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
}
