:root {
    --sidebar-width: 200px;
    --sidebar-min: 180px;
    --sidebar-max: 250px;
    --bg: #f4f6fb;
    --text: #0f172a;
    --muted: #64748b;
    --border: #e2e8f0;
    --surface: #ffffff;
    --input-focus-ring: rgba(13, 148, 136, 0.25);
    --primary: #0d9488;
    --primary-dark: #0f766e;
    --accent: #2563eb;
    --warn: #f59e0b;
    --sidebar: #0b1220;
    --sidebar-text: #cbd5e1;
    --radius: 14px;
    --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
    --font: "Noto Sans TC", system-ui, sans-serif;
}

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

html, body {
    margin: 0;
    padding: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

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

.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    min-height: 100vh;
}

.sidebar-shell {
    position: sticky;
    top: 0;
    display: flex;
    height: 100vh;
    z-index: 30;
    min-width: 0;
}

.sidebar {
    background: linear-gradient(180deg, #0b1220 0%, #111827 100%);
    color: var(--sidebar-text);
    padding: 1.25rem 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    flex: 1;
    min-width: 0;
    height: 100%;
    overflow: hidden;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem;
}

.brand-mark {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--primary), #14b8a6);
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 1.1rem;
}

.brand strong { display: block; color: #fff; font-size: 1rem; }
.brand small { color: #94a3b8; font-size: 0.75rem; }

.tenant-chip {
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 12px;
    padding: 0.75rem;
    display: grid;
    gap: 0.15rem;
}

.tenant-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; color: #94a3b8; }
.tenant-chip code { font-size: 0.75rem; color: #5eead4; }

.nav { display: flex; flex-direction: column; gap: 0.2rem; flex: 1; min-height: 0; overflow-y: auto; padding-right: 0.15rem; }

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.7rem 0.85rem;
    border-radius: 10px;
    color: var(--sidebar-text);
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
}

.nav-link:hover { background: rgba(255,255,255,0.06); color: #fff; text-decoration: none; }
.nav-link.is-active { background: rgba(13, 148, 136, 0.25); color: #fff; }

.nav-icon { opacity: 0.85; width: 1.1rem; text-align: center; flex-shrink: 0; }

.nav-group {
    border-radius: 10px;
}

.nav-group-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    width: 100%;
    padding: 0.65rem 0.85rem;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: var(--sidebar-text);
    font: inherit;
    font-size: 0.92rem;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s, color 0.15s;
}

.nav-group-toggle:hover { background: rgba(255,255,255,0.06); color: #fff; }

.nav-group-label {
    display: flex;
    align-items: center;
    gap: 0.65rem;
}

.nav-chevron {
    font-size: 0.7rem;
    opacity: 0.7;
    transition: transform 0.2s ease;
}

.nav-group.is-open .nav-chevron { transform: rotate(0deg); }
.nav-group:not(.is-open) .nav-chevron { transform: rotate(-90deg); }

.nav-group-items {
    display: none;
    flex-direction: column;
    gap: 0.1rem;
    padding: 0.15rem 0 0.35rem 0.35rem;
}

.nav-group.is-open .nav-group-items { display: flex; }

.nav-sublink {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.45rem 0.75rem 0.45rem 2rem;
    border-radius: 8px;
    color: #94a3b8;
    font-size: 0.88rem;
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
}

.nav-sublink:hover { background: rgba(255,255,255,0.05); color: #e2e8f0; text-decoration: none; }
.nav-sublink.is-active { background: rgba(13, 148, 136, 0.2); color: #fff; }
.nav-sublink.is-soon { opacity: 0.92; }

.nav-tag {
    font-size: 0.65rem;
    padding: 0.1rem 0.35rem;
    border-radius: 4px;
    background: rgba(255,255,255,0.1);
    color: #cbd5e1;
    flex-shrink: 0;
}

.placeholder-panel .placeholder-lead {
    margin: 0 0 1rem;
    color: var(--muted);
    font-size: 0.95rem;
}

.placeholder-meta {
    margin: 0;
    display: grid;
    gap: 0.75rem;
}

.placeholder-meta div {
    display: grid;
    gap: 0.2rem;
}

.placeholder-meta dt {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.placeholder-meta dd {
    margin: 0;
    font-size: 0.92rem;
}

.logout-link {
    font-size: 0.85rem;
    color: var(--muted);
    margin-left: 0.5rem;
}

.logout-link:hover { color: var(--primary-dark); }

.sidebar-foot { font-size: 0.75rem; color: #64748b; padding: 0.5rem; }

.main { min-width: 0; display: flex; flex-direction: column; }

.topbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.25rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
}

.menu-toggle { display: none; }

.topbar-title h1 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
}

.topbar-title p {
    margin: 0.15rem 0 0;
    font-size: 0.85rem;
    color: var(--muted);
}

.user-pill {
    margin-left: auto;
    background: #ecfeff;
    color: var(--primary-dark);
    padding: 0.4rem 0.75rem;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 500;
}

.content {
    padding: 1.25rem;
    display: grid;
    gap: 1rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1rem;
}

.stat-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1rem 1.1rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.stat-card.accent { border-color: #99f6e4; background: linear-gradient(180deg, #fff, #f0fdfa); }

.stat-label { display: block; font-size: 0.85rem; color: var(--muted); }
.stat-value { display: block; font-size: 1.75rem; font-weight: 700; margin: 0.25rem 0; }
.stat-meta { font-size: 0.8rem; color: var(--muted); }

.panel-grid {
    display: grid;
    grid-template-columns: 1.4fr 0.9fr;
    gap: 1rem;
}

.panel, .note-panel {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    padding: 1rem 1.1rem;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.85rem;
}

.panel-head h2 { margin: 0; font-size: 1.05rem; }

.toolbar {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 0.85rem;
    flex-wrap: wrap;
}

.toolbar .search-input,
.toolbar .select {
    min-width: 200px;
}

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
}

.data-table th, .data-table td {
    padding: 0.65rem 0.5rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}

.data-table th { color: var(--muted); font-weight: 600; font-size: 0.8rem; white-space: nowrap; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table tr.row-warn { background: #fffbeb; }

.lines-cell { max-width: 280px; font-size: 0.85rem; color: var(--muted); }

.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    background: #f1f5f9;
    color: #475569;
}

.badge.ok { background: #ecfdf5; color: #047857; }
.badge.accent { background: #eff6ff; color: #1d4ed8; }
.badge.warn { background: #fffbeb; color: #b45309; }

.actions-cell {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 0.75rem;
    white-space: nowrap;
}

.inline-form { display: inline; margin: 0; }

.btn-link {
    border: none;
    background: none;
    padding: 0;
    font: inherit;
    color: var(--accent);
    cursor: pointer;
    text-decoration: underline;
}

.btn-link.warn { color: #b45309; }

.alert {
    border-radius: 10px;
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    font-size: 0.92rem;
}

.alert-success {
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
    color: #047857;
}

.alert-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #b91c1c;
}

.error-list {
    margin: 0;
    padding-left: 1.2rem;
}

/* 表單版面（.form-grid／.form-field／.form-actions／.checkbox-row）集中於 ylso-shared.css，勿在此重複 */

.btn {
    border: 1px solid var(--border);
    background: #fff;
    border-radius: 10px;
    padding: 0.5rem 0.85rem;
    font: inherit;
    cursor: pointer;
}

.btn.primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.link { font-size: 0.85rem; }

.alert-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.65rem; }
.alert-list li {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.55rem 0;
    border-bottom: 1px dashed var(--border);
    font-size: 0.9rem;
}

.muted { color: var(--muted); }
.note-panel p { margin: 0.5rem 0 0; color: var(--muted); font-size: 0.92rem; }
.note-panel code { font-size: 0.85em; }

.icon-btn {
    border: none;
    background: #f1f5f9;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    font-size: 1.1rem;
    cursor: pointer;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 25;
}

@media (max-width: 1024px) {
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .panel-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .app-shell { grid-template-columns: 1fr; }

    .sidebar-shell {
        position: fixed;
        left: 0;
        top: 0;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        width: min(280px, 86vw);
        height: 100vh;
        z-index: 30;
    }

    .sidebar-shell.is-open { transform: translateX(0); }
    .sidebar-overlay.is-visible { display: block; }

    .menu-toggle { display: inline-grid; place-items: center; }

    .topbar-title p { display: none; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .content { padding: 0.85rem; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .user-pill { display: none; }
}
