@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=Noto+Sans+TC:wght@300;400;500;700&display=swap');

/* ─── Design Tokens ─── */
:root {
    /* Primary Palette — deep indigo / violet */
    --color-primary: #6366f1;
    --color-primary-dark: #4f46e5;
    --color-primary-light: #818cf8;
    --color-primary-surface: rgba(99, 102, 241, 0.08);

    /* Surfaces */
    --color-bg: #f0f2f5;
    --color-sidebar: #0f172a;
    --color-sidebar-surface: #1e293b;
    --color-sidebar-hover: #334155;
    --color-card: #ffffff;

    /* Text */
    --color-text: #0f172a;
    --color-text-secondary: #475569;
    --color-text-muted: #94a3b8;
    --color-text-inverse: #ffffff;

    /* Borders */
    --color-border: #e2e8f0;
    --color-border-light: #f1f5f9;

    /* Semantic */
    --color-success: #10b981;
    --color-success-bg: rgba(16, 185, 129, 0.1);
    --color-warning: #f59e0b;
    --color-warning-bg: rgba(245, 158, 11, 0.1);
    --color-error: #ef4444;
    --color-error-bg: rgba(239, 68, 68, 0.1);
    --color-info: #3b82f6;
    --color-info-bg: rgba(59, 130, 246, 0.1);

    /* Radii */
    --radius-xs: 6px;
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.04);
    --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.15);

    /* Transitions */
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --transition: all 0.2s var(--ease-out);
    --transition-slow: all 0.35s var(--ease-out);
}

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

body {
    font-family: 'Inter', 'Noto Sans TC', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ─── Layout ─── */
.admin-container {
    display: flex;
    min-height: 100vh;
}

/* ─── Sidebar ─── */
.sidebar {
    width: 272px;
    background: var(--color-sidebar);
    color: var(--color-text-inverse);
    padding: 28px 16px;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
    z-index: 100;
    display: flex;
    flex-direction: column;
}

.sidebar::-webkit-scrollbar {
    width: 4px;
}

.sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
}

.logo {
    font-size: 20px;
    font-weight: 800;
    margin-bottom: 8px;
    padding: 4px 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    background: linear-gradient(135deg, #fff 0%, #a5b4fc 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.02em;
}

.logo h2 {
    font-size: 20px;
    font-weight: 800;
    background: linear-gradient(135deg, #fff 0%, #a5b4fc 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.logo p,
.logo span {
    font-size: 11px;
    font-weight: 400;
    -webkit-text-fill-color: var(--color-text-muted);
    opacity: 0.7;
    letter-spacing: 0.04em;
}

/* Sidebar nav */
.sidebar nav,
.nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 24px;
    flex: 1;
}

.sidebar nav a,
.sidebar .nav-item {
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    color: rgba(255, 255, 255, 0.65) !important;
    text-decoration: none !important;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
    font-weight: 500;
    position: relative;
    overflow: hidden;
}

.sidebar nav a::before,
.sidebar .nav-item::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: var(--radius-sm);
    opacity: 0;
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
    transition: opacity 0.2s ease;
    z-index: -1;
}

.sidebar nav a:hover,
.sidebar .nav-item:hover {
    color: rgba(255, 255, 255, 0.95) !important;
    background: var(--color-sidebar-hover);
    transform: translateX(2px);
}

.sidebar nav a.active,
.sidebar .nav-item.active {
    color: white !important;
    font-weight: 600;
}

.sidebar nav a.active::before,
.sidebar .nav-item.active::before {
    opacity: 1;
}

.sidebar nav a.active {
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.35);
}

/* Nav icon emoji sizing */
.sidebar nav a span:first-child,
.sidebar .nav-item span:first-child {
    font-size: 18px;
    width: 24px;
    text-align: center;
    flex-shrink: 0;
}

/* ─── Tenant Switcher ─── */
.tenant-switcher {
    margin-top: auto;
    padding: 16px;
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(8px);
}

.tenant-switcher__title {
    font-weight: 600;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.8);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.tenant-switcher__label {
    display: block;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.5);
    margin-bottom: 6px;
}

.tenant-switcher__input {
    width: 100%;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(0, 0, 0, 0.3);
    color: #fff;
    font-size: 13px;
    margin-bottom: 10px;
    font-family: inherit;
    transition: var(--transition);
}

.tenant-switcher__input:focus {
    outline: none;
    border-color: var(--color-primary-light);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.tenant-switcher__actions {
    display: flex;
    gap: 6px;
}

.tenant-switcher__btn {
    flex: 1;
    border: none;
    border-radius: var(--radius-sm);
    padding: 8px 0;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    background: var(--color-primary);
    color: #fff;
    transition: var(--transition);
}

.tenant-switcher__btn:hover {
    background: var(--color-primary-dark);
}

.tenant-switcher__btn.ghost {
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.7);
}

.tenant-switcher__btn.ghost:hover {
    background: rgba(255, 255, 255, 0.15);
}

.tenant-switcher__hint {
    margin-top: 8px;
    font-size: 10px;
    color: rgba(255, 255, 255, 0.4);
}

.tenant-switcher__badge {
    background: rgba(99, 102, 241, 0.25);
    color: #a5b4fc;
    font-weight: 600;
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    font-size: 0.9rem;
    text-align: center;
    letter-spacing: 0.5px;
    border: 1px solid rgba(99, 102, 241, 0.3);
}

.tenant-switcher__logout {
    margin-top: 0.5rem;
}

/* ─── Main Content ─── */
.main-content {
    flex: 1;
    margin-left: 272px;
    padding: 32px 40px;
    min-height: 100vh;
    background: var(--color-bg);
}

/* ─── Page Header ─── */
header {
    margin-bottom: 32px;
}

h1 {
    font-size: 28px;
    font-weight: 800;
    color: var(--color-text);
    letter-spacing: -0.02em;
    margin-bottom: 4px;
}

h2 {
    font-size: 18px;
    font-weight: 700;
    color: var(--color-text);
    margin-bottom: 20px;
    letter-spacing: -0.01em;
}

/* ─── Cards ─── */
.card {
    background: var(--color-card);
    padding: 24px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    margin-bottom: 24px;
    border: 1px solid var(--color-border-light);
    transition: var(--transition);
}

.card:hover {
    box-shadow: var(--shadow-md);
}

/* ─── Stats Grid ─── */
.stats,
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 28px;
}

.stats .stat-card,
.stats-grid .stat-card {
    background: var(--color-card);
    padding: 24px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: 18px;
    transition: var(--transition);
    border: 1px solid var(--color-border-light);
    position: relative;
    overflow: hidden;
}

.stats .stat-card::after,
.stats-grid .stat-card::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--color-primary) 0%, var(--color-primary-light) 100%);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.stats .stat-card:hover,
.stats-grid .stat-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
}

.stats .stat-card:hover::after,
.stats-grid .stat-card:hover::after {
    opacity: 1;
}

.stat-card h3 {
    font-size: 12px;
    font-weight: 600;
    color: var(--color-text-muted);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.stat-card .stat-value,
.stat-card p.stat-value {
    font-size: 32px;
    font-weight: 800;
    color: var(--color-text);
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
}

.stat-icon {
    width: 56px;
    height: 56px;
    background: linear-gradient(135deg, var(--color-primary-light) 0%, var(--color-primary) 100%);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.25);
}

.stat-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--color-text-muted);
    margin-top: 2px;
}

/* ─── Search Bar ─── */
.search-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.search-bar input {
    flex: 1;
    min-width: 250px;
    padding: 12px 18px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 14px;
    transition: var(--transition);
    background: var(--color-card);
    font-family: inherit;
    color: var(--color-text);
}

.search-bar input::placeholder {
    color: var(--color-text-muted);
}

.search-bar input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-surface);
}

.search-bar button {
    padding: 12px 24px;
    font-size: 14px;
    font-weight: 600;
}

/* ─── Buttons ─── */
button,
.btn-primary,
.btn-secondary {
    padding: 10px 20px;
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

button:hover,
.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
}

button:active,
.btn-primary:active {
    transform: translateY(0);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-secondary {
    background: var(--color-card);
    color: var(--color-text);
    border: 1px solid var(--color-border);
}

.btn-secondary:hover {
    background: var(--color-bg);
    box-shadow: var(--shadow-sm);
}

.btn-small {
    padding: 6px 14px;
    font-size: 13px;
    border-radius: var(--radius-xs);
}

.btn-danger {
    background: linear-gradient(135deg, var(--color-error) 0%, #dc2626 100%);
}

.btn-danger:hover {
    box-shadow: 0 4px 14px rgba(239, 68, 68, 0.35);
}

.btn-success {
    background: linear-gradient(135deg, var(--color-success) 0%, #059669 100%);
}

.btn-success:hover {
    box-shadow: 0 4px 14px rgba(16, 185, 129, 0.35);
}

.btn-edit {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
}

.btn-edit:hover {
    box-shadow: 0 4px 14px rgba(245, 158, 11, 0.35);
}

/* ─── Table ─── */
.table-container {
    overflow-x: auto;
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-lg);
    background: var(--color-card);
    box-shadow: var(--shadow-xs);
}

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 14px;
    min-width: 800px;
}

thead {
    position: sticky;
    top: 0;
    z-index: 2;
}

th {
    text-align: center;
    padding: 14px 18px;
    font-weight: 600;
    color: var(--color-text-secondary);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    background: var(--color-bg);
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
}

th:first-child {
    border-radius: var(--radius-lg) 0 0 0;
}

th:last-child {
    border-radius: 0 var(--radius-lg) 0 0;
}

td {
    padding: 16px 18px;
    border-bottom: 1px solid var(--color-border-light);
    color: var(--color-text);
    text-align: center;
    vertical-align: middle;
    font-size: 14px;
}

td:first-child {
    text-align: left;
    font-weight: 500;
}

tbody tr {
    transition: var(--transition);
}

tbody tr:hover {
    background: var(--color-primary-surface);
}

tbody tr:last-child td {
    border-bottom: none;
}

tbody tr:last-child td:first-child {
    border-radius: 0 0 0 var(--radius-lg);
}

tbody tr:last-child td:last-child {
    border-radius: 0 0 var(--radius-lg) 0;
}

td button {
    padding: 6px 12px;
    font-size: 12px;
    margin: 2px;
}

/* ─── Status Badges ─── */
.status-badge {
    padding: 4px 12px;
    border-radius: var(--radius-full);
    font-size: 12px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.status-pending {
    background: var(--color-warning-bg);
    color: #92400e;
}

.status-completed {
    background: var(--color-success-bg);
    color: #065f46;
}

.status-cancelled {
    background: var(--color-error-bg);
    color: #991b1b;
}

/* ─── Pagination ─── */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-top: 24px;
    padding-top: 24px;
    border-top: 1px solid var(--color-border-light);
}

.pagination button {
    padding: 8px 18px;
    font-size: 13px;
}

.pagination #pageInfo {
    color: var(--color-text-muted);
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}

/* ─── Modal ─── */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 1000;
    overflow-y: auto;
    padding: 40px 20px;
}

.modal-content {
    background: var(--color-card);
    max-width: 720px;
    width: 95%;
    margin: 0 auto;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    position: relative;
    animation: modalSlideIn 0.35s var(--ease-out);
    border: 1px solid var(--color-border-light);
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-16px) scale(0.98);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-content h2 {
    padding: 24px 28px;
    border-bottom: 1px solid var(--color-border-light);
    margin-bottom: 0;
    font-size: 18px;
}

.modal-content .close {
    position: absolute;
    top: 18px;
    right: 24px;
    font-size: 24px;
    cursor: pointer;
    color: var(--color-text-muted);
    transition: var(--transition);
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    background: transparent;
    box-shadow: none;
}

.modal-content .close:hover {
    color: var(--color-text);
    background: var(--color-bg);
}

/* ─── Customer Info in Modal ─── */
.customer-info {
    padding: 24px 28px;
}

.info-row {
    display: flex;
    padding: 12px 0;
    border-bottom: 1px solid var(--color-border-light);
}

.info-row:last-child {
    border-bottom: none;
}

.info-row .label {
    width: 140px;
    font-weight: 500;
    color: var(--color-text-muted);
    font-size: 14px;
}

.info-row .value {
    flex: 1;
    font-weight: 600;
    color: var(--color-text);
}

.detail-table {
    margin: 0 28px 24px;
    width: calc(100% - 56px);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius);
    overflow: hidden;
    min-width: auto;
}

.detail-table thead {
    background: var(--color-bg);
}

.detail-table th {
    padding: 10px 14px;
    font-size: 12px;
    text-align: center;
    border-bottom: 1px solid var(--color-border);
}

.detail-table td {
    padding: 10px 14px;
    font-size: 13px;
    text-align: center;
    border-bottom: 1px solid var(--color-border-light);
}

.detail-table td:first-child {
    text-align: center;
}

.detail-table tbody tr:last-child td {
    border-bottom: none;
}

.detail-table tbody tr:nth-child(even) {
    background: rgba(248, 250, 252, 0.5);
}

/* Modal h3 */
.modal-content h3 {
    padding: 16px 28px 8px;
    font-size: 15px;
    font-weight: 700;
    color: var(--color-text);
}

/* ─── Form Styles ─── */
.form-container,
form {
    padding: 24px 28px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    color: var(--color-text);
    font-size: 13px;
    letter-spacing: 0.01em;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    transition: var(--transition);
    background: var(--color-card);
    color: var(--color-text);
}

.form-group input::placeholder,
.form-group textarea::placeholder {
    color: var(--color-text-muted);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-surface);
}

.form-group textarea {
    resize: vertical;
    min-height: 100px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
}

.form-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    padding-top: 16px;
    border-top: 1px solid var(--color-border-light);
    margin-top: 8px;
}

/* ─── Responsive ─── */
@media (max-width: 1024px) {
    .sidebar {
        width: 72px;
        padding: 20px 8px;
    }

    .logo {
        font-size: 0;
        padding: 8px;
        text-align: center;
    }

    .logo h2 {
        display: none;
    }

    .logo p,
    .logo span {
        display: none;
    }

    .logo::after {
        content: '🏠';
        font-size: 24px;
        -webkit-text-fill-color: initial;
    }

    /* Hide nav text, show only icon */
    .sidebar nav a,
    .sidebar .nav-item {
        justify-content: center;
        padding: 12px;
        font-size: 0;
    }

    .sidebar nav a span:first-child,
    .sidebar .nav-item span:first-child {
        font-size: 20px;
    }

    .tenant-switcher {
        display: none;
    }

    .main-content {
        margin-left: 72px;
        padding: 24px;
    }
}

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        bottom: 0;
        top: auto;
        left: 0;
        right: 0;
        width: 100%;
        height: 64px;
        flex-direction: row;
        padding: 4px 8px;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
        z-index: 200;
    }

    .logo {
        display: none;
    }

    .tenant-switcher {
        display: none;
    }

    .sidebar nav,
    .nav {
        flex-direction: row;
        justify-content: space-around;
        margin-top: 0;
        width: 100%;
    }

    .sidebar nav a,
    .sidebar .nav-item {
        padding: 8px;
        font-size: 0;
        flex-direction: column;
        gap: 2px;
    }

    .sidebar nav a span:first-child,
    .sidebar .nav-item span:first-child {
        font-size: 20px;
    }

    .main-content {
        margin-left: 0;
        padding: 16px;
        padding-bottom: 80px;
        /* Space for bottom nav */
    }

    .stats,
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    h1 {
        font-size: 22px;
    }
}

/* ─── Animations ─── */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(12px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.stat-card {
    animation: fadeInUp 0.4s var(--ease-out) backwards;
}

.stat-card:nth-child(1) {
    animation-delay: 0.05s;
}

.stat-card:nth-child(2) {
    animation-delay: 0.1s;
}

.stat-card:nth-child(3) {
    animation-delay: 0.15s;
}

.stat-card:nth-child(4) {
    animation-delay: 0.2s;
}

/* ─── Utility classes ─── */
.text-success {
    color: var(--color-success);
}

.text-warning {
    color: var(--color-warning);
}

.text-error {
    color: var(--color-error);
}

.text-info {
    color: var(--color-info);
}

.text-muted {
    color: var(--color-text-muted);
}

.font-mono {
    font-variant-numeric: tabular-nums;
    font-family: 'SF Mono', 'Fira Code', monospace;
}