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

:root {
    --primary: #0d9488;
    --primary-hover: #0f766e;
    --primary-soft: #e9fbf8;
    --danger: #ef4444;
    --success: #16a34a;
    --warning: #d97706;
    --bg: #eef8f7;
    --card-bg: #ffffff;
    --border: #e5edf4;
    --border-strong: #d7e2ec;
    --text: #0f172a;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --shadow-soft: 0 10px 28px rgba(15, 23, 42, 0.06);
    --radius: 8px;
}

html, body { min-height: 100%; }
html { overflow-x: hidden; }

body {
    min-height: 100vh;
    background: linear-gradient(135deg, #f8fcfc 0%, var(--bg) 52%, #f7fbfb 100%);
    color: var(--text);
    font-family: "Aptos", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    line-height: 1.5;
}

button, input, select, textarea { font: inherit; }
button { user-select: none; }

#loginPage {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: #f0fdfa;
}

#loginPage.login-hidden { display: none; }

.login-box {
    width: 390px;
    max-width: 100%;
    padding: 34px;
    border: 1px solid rgba(255, 255, 255, 0.72);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: 0 28px 76px rgba(15, 23, 42, 0.2);
}

.login-box h2 {
    margin-bottom: 24px;
    text-align: center;
    font-size: 24px;
    font-weight: 900;
}

.login-error,
.form-error {
    min-height: 20px;
    margin-top: 8px;
    color: var(--danger);
    font-size: 13px;
}

.app-shell {
    display: grid;
    grid-template-columns: 240px minmax(0, 1fr);
    min-height: 100vh;
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    max-width: 100%;
    display: flex;
    flex-direction: column;
    overflow-x: clip;
    padding: 18px 14px;
    border-right: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 8px 0 24px rgba(15, 23, 42, 0.03);
}

.brand-block {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 10px 22px;
    flex-shrink: 0;
}

.brand-mark {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: #ccfbf1;
    color: var(--primary-hover);
    font-size: 20px;
    font-weight: 900;
}

.brand-block h1 { font-size: 21px; line-height: 1.15; }
.brand-block p { color: var(--text-secondary); font-size: 12px; }

.nav-tabs {
    display: flex;
    flex: 1;
    min-height: 0;
    max-width: 100%;
    flex-direction: column;
    gap: 7px;
    overflow-x: clip;
    overflow-y: auto;
}

.nav-tab {
    width: 100%;
    min-width: 0;
    min-height: 48px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 18px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: #475569;
    cursor: pointer;
    text-align: left;
    transition: background 0.16s ease, color 0.16s ease, transform 0.16s ease;
}

.nav-tab svg {
    width: 18px;
    height: 18px;
    flex: 0 0 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.nav-tab span { display: none; }
.nav-tab strong { font-size: 15px; font-weight: 800; }
.nav-tab:hover { transform: translateX(2px); background: #f0fdfa; color: var(--primary-hover); }
.nav-tab.active { background: var(--primary-soft); color: var(--primary); }

.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-top: 14px;
    padding: 11px 13px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    cursor: pointer;
    font-weight: 800;
}

.theme-toggle strong {
    min-width: 32px;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--primary-soft);
    color: var(--primary);
    text-align: center;
}

.workspace { min-width: 0; padding: 0 28px 28px; }

.workspace-header {
    position: sticky;
    top: 0;
    z-index: 60;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin: 0 -28px 24px;
    padding: 16px 38px;
    border-bottom: 1px solid var(--border);
    background: rgba(248, 252, 252, 0.94);
    backdrop-filter: blur(18px);
}

.workspace-header h2 { font-size: 25px; line-height: 1.15; font-weight: 900; }
.eyebrow { margin-top: 2px; color: var(--text-secondary); font-size: 13px; }
.main-container { max-width: 1510px; margin: 0 auto; }

.topbar-actions { display: flex; align-items: center; gap: 18px; }
.profile-menu { position: relative; }

.profile-trigger {
    display: flex;
    align-items: center;
    gap: 10px;
    border: none;
    background: transparent;
    color: var(--text);
    cursor: pointer;
}

.profile-avatar {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: #14b8a6;
    color: #fff;
    font-size: 18px;
    font-weight: 900;
}

.profile-text { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.2; }
.profile-text small { color: var(--text-secondary); font-size: 13px; }
.profile-chevron svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; }

.profile-dropdown {
    position: absolute;
    top: calc(100% + 12px);
    right: 0;
    width: 230px;
    display: none;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 22px 60px rgba(15, 23, 42, 0.16);
}

.profile-menu.open .profile-dropdown { display: block; }
.profile-dropdown-head { padding: 14px 16px; border-bottom: 1px solid #eef2f7; }
.profile-dropdown-head strong, .profile-dropdown-head small { display: block; }
.profile-dropdown-head small { margin-top: 2px; color: var(--text-secondary); }

.profile-dropdown button {
    width: 100%;
    padding: 13px 16px;
    border: none;
    border-bottom: 1px solid #eef2f7;
    background: #fff;
    color: #334155;
    cursor: pointer;
    text-align: left;
    font-size: 14px;
}

.profile-dropdown button:hover { background: #f8fafc; }
.profile-dropdown .dropdown-danger { color: var(--danger); }

.tab-content { display: none; }
.tab-content.active { display: block; }

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

.stat-card {
    min-height: 110px;
    padding: 20px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.9);
    box-shadow: var(--shadow-soft);
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.stat-card:hover { transform: translateY(-2px); box-shadow: 0 14px 32px rgba(15, 23, 42, 0.12); }
.stat-num { font-size: 30px; font-weight: 900; }
.stat-label { margin-top: 8px; color: var(--text-secondary); font-size: 13px; font-weight: 800; }

.toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 14px;
    padding: 13px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.88);
    box-shadow: var(--shadow-soft);
}

.toolbar-right { display: flex; align-items: center; gap: 9px; margin-left: auto; flex-wrap: wrap; justify-content: flex-end; }

.toolbar select,
.toolbar input,
.form-group input,
.form-group select,
.form-group textarea {
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    outline: none;
    transition: border 0.18s ease, box-shadow 0.18s ease;
}

.toolbar select, .toolbar input { min-height: 38px; padding: 7px 10px; font-size: 13px; }
.toolbar input { width: 190px; }

.toolbar select:focus,
.toolbar input:focus,
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: #5eead4;
    box-shadow: 0 0 0 4px rgba(20, 184, 166, 0.16);
}

.btn {
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 8px 14px;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    cursor: pointer;
    font-size: 13px;
    font-weight: 800;
    transition: transform 0.16s ease, background 0.16s ease, border 0.16s ease, color 0.16s ease;
}

.btn:hover { transform: translateY(-1px); background: #f8fafc; }
.btn-primary { border-color: var(--primary); background: #0d9488; color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { border-color: #fecaca; color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); background: var(--danger); color: #fff; }
.btn-sm { min-height: 30px; padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; min-height: 44px; font-size: 15px; }
.btn-plus { font-size: 18px; line-height: 1; }

.table-wrap {
    max-height: 66vh;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    box-shadow: var(--shadow-soft);
}

.table-wrap::-webkit-scrollbar { width: 6px; height: 6px; }
.table-wrap::-webkit-scrollbar-track { background: transparent; }
.table-wrap::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 6px; }

table { width: 100%; min-width: max-content; border-collapse: collapse; }
th, td { padding: 13px 15px; text-align: left; white-space: nowrap; font-size: 13px; }

th {
    position: sticky;
    top: 0;
    z-index: 3;
    border-bottom: 1px solid var(--border);
    background: #f8fafc;
    color: #475569;
    font-size: 12px;
    font-weight: 900;
}

td { border-bottom: 1px solid #edf2f7; color: #26364d; }
tr:hover td { background: #f8fffd; }
tr:last-child td { border-bottom: none; }
th:last-child, td:last-child { position: sticky; right: 0; z-index: 1; background: #fff; box-shadow: -4px 0 8px rgba(15, 23, 42, 0.06); }
th:last-child { z-index: 4; background: #f8fafc; }
tr:hover td:last-child { background: #f8fffd; }

.cell-link { color: var(--primary); font-weight: 800; cursor: pointer; text-decoration: none; }
.cell-link:hover { text-decoration: underline; }
.muted { color: var(--text-muted); }
.empty-text { padding: 28px 16px; color: var(--text-muted); text-align: center; }
.actions { display: flex; gap: 6px; align-items: center; }
.toolbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.inline-control { display: flex; align-items: stretch; gap: 8px; }
.inline-control select { flex: 1; min-width: 0; }
.btn-icon { width: 40px; padding: 0; justify-content: center; font-size: 18px; font-weight: 800; }
.bulk-result { margin-top: 10px; color: var(--text-secondary); font-size: 13px; }
.bulk-result ul { margin-top: 8px; padding-left: 18px; color: var(--danger); }
.qr-box { display: grid; gap: 14px; justify-items: center; }
.qr-box img { width: 220px; height: 220px; border: 1px solid var(--border); border-radius: 8px; background: #fff; padding: 8px; }
.qr-box textarea { width: 100%; }
.binding-list { display: flex; flex-wrap: wrap; gap: 6px; max-width: 260px; }
.binding-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    min-height: 26px;
    padding: 3px 7px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--primary-soft);
}
.binding-chip button {
    width: 18px;
    height: 18px;
    border: none;
    border-radius: 50%;
    background: rgba(15, 118, 110, 0.14);
    color: var(--primary-hover);
    cursor: pointer;
    line-height: 1;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 850;
}

.badge-active, .badge-normal { background: #dcfce7; color: #15803d; }
.badge-idle { background: #dbeafe; color: #1d4ed8; }
.badge-maintenance, .badge-frozen { background: #fef3c7; color: #b45309; }
.badge-retired, .badge-disabled { background: #f1f5f9; color: #64748b; }
.badge-banned, .badge-expired { background: #fee2e2; color: #dc2626; }

.pagination {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    margin-top: 14px;
    font-size: 13px;
    font-weight: 600;
}

.pagination-inner { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.pagination-btns { display: flex; align-items: center; gap: 3px; }
.pagination-info { color: var(--text-muted); font-size: 12px; white-space: nowrap; }

.page-arrow, .page-num {
    min-width: 30px;
    height: 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--card-bg);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 12px;
    font-weight: 800;
}

.page-num.active { border-color: var(--primary); background: var(--primary); color: #fff; }
.page-arrow[disabled] { cursor: not-allowed; opacity: 0.4; }
.page-dots { min-width: 30px; text-align: center; color: var(--text-muted); }
.page-size-select { margin-left: 4px; padding: 2px 6px; border: 1px solid var(--border); border-radius: 6px; background: var(--card-bg); color: var(--text-secondary); }

.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding: 50px 20px;
    background: rgba(15, 23, 42, 0.46);
    backdrop-filter: blur(8px);
}

.modal-overlay.active { display: flex; }

.modal {
    width: 520px;
    max-width: 100%;
    max-height: 84vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.72);
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 28px 80px rgba(15, 23, 42, 0.24);
}

.modal-lg { width: 760px; }

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 22px;
    border-bottom: 1px solid var(--border);
    background: #f8fbff;
}

.modal-header h3 { font-size: 18px; }
.modal-close { width: 32px; height: 32px; border: none; border-radius: 8px; background: #eef2f7; color: var(--text-secondary); cursor: pointer; font-size: 22px; line-height: 1; }
.modal-body { flex: 1; min-height: 0; overflow-y: auto; padding: 22px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 15px 22px; border-top: 1px solid var(--border); background: #fbfdff; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.form-group { display: flex; flex-direction: column; gap: 7px; margin-bottom: 14px; }
.form-grid .form-group { margin-bottom: 0; }
.field-full { grid-column: 1 / -1; }

.form-group label { color: var(--text-secondary); font-size: 13px; font-weight: 800; }
.form-group input, .form-group select, .form-group textarea { width: 100%; min-height: 40px; padding: 8px 11px; font-size: 14px; }
.form-group textarea { min-height: 84px; resize: vertical; }
.form-group select[multiple] { min-height: 130px; padding: 8px; }
.required { color: var(--danger); }
.field-help { color: var(--text-muted); font-size: 12px; }

.app-dialog {
    width: 380px;
    max-width: 100%;
    padding: 24px;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 26px 76px rgba(15, 23, 42, 0.26);
    text-align: center;
}

.app-dialog-icon {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    margin: 0 auto 12px;
    border-radius: 999px;
    background: var(--primary-soft);
    color: var(--primary);
    font-weight: 900;
}

.app-dialog h3 { margin-bottom: 8px; font-size: 18px; }
.app-dialog p { color: var(--text-secondary); font-size: 14px; }
.app-dialog-actions { display: flex; justify-content: center; gap: 10px; margin-top: 20px; }

.menu-toggle-btn {
    display: none;
    width: 42px;
    height: 42px;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--card-bg);
    color: var(--text);
    cursor: pointer;
}

.menu-toggle-btn svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 2; }

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 80;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(2px);
}

body.dark-mode {
    --bg: #0f172a;
    --card-bg: #111827;
    --border: #263244;
    --border-strong: #334155;
    --text: #e5eef8;
    --text-secondary: #9fb0c4;
    --text-muted: #64748b;
    background: linear-gradient(135deg, #08111f 0%, #0f172a 55%, #111827 100%);
}

body.dark-mode .sidebar,
body.dark-mode .workspace-header,
body.dark-mode .stat-card,
body.dark-mode .toolbar,
body.dark-mode .table-wrap,
body.dark-mode .modal,
body.dark-mode .profile-dropdown,
body.dark-mode .theme-toggle,
body.dark-mode .app-dialog {
    background: #111827;
    color: var(--text);
    border-color: var(--border);
}

body.dark-mode th,
body.dark-mode .modal-header,
body.dark-mode .modal-footer { background: #172033; }
body.dark-mode td,
body.dark-mode .profile-dropdown button { background: #111827; color: var(--text); border-color: var(--border); }
body.dark-mode tr:hover td,
body.dark-mode tr:hover td:last-child { background: #1e293b; }
body.dark-mode th:last-child { background: #172033; }
body.dark-mode td:last-child { background: #111827; }

body.dark-mode .toolbar input,
body.dark-mode .toolbar select,
body.dark-mode .form-group input,
body.dark-mode .form-group select,
body.dark-mode .form-group textarea {
    background: #0f172a;
    color: #e5eef8;
    border-color: #334155;
}

body.dark-mode .btn { background: #172033; color: #e5eef8; border-color: #334155; }
body.dark-mode .btn-primary { background: #0d9488; color: #fff; border-color: #0d9488; }
body.dark-mode .btn-danger { color: #fecaca; border-color: #7f1d1d; }
body.dark-mode .cell-link { color: #5eead4; }
body.dark-mode .modal-close { background: #263244; color: #cbd5e1; }

@media (max-width: 1200px) {
    .app-shell { grid-template-columns: 220px minmax(0, 1fr); }
    .stats-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 900px) {
    .app-shell { grid-template-columns: 1fr; }
    .menu-toggle-btn { display: flex; }
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        z-index: 100;
        width: 280px;
        max-width: 85vw;
        height: 100vh;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: 8px 0 32px rgba(15, 23, 42, 0.18);
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay.show { display: block; }
    .workspace { padding: 0 16px 16px; }
    .workspace-header { margin: 0 -16px 20px; padding: 15px 16px; }
    .workspace-header > div { flex: 1; min-width: 0; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .toolbar { align-items: stretch; flex-direction: column; }
    .toolbar-right { width: 100%; margin-left: 0; flex-direction: column; align-items: stretch; }
    .toolbar input, .toolbar select { width: 100%; }
    .form-grid { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
    .stats-grid { grid-template-columns: 1fr; }
    .workspace-header h2 { font-size: 22px; }
    .profile-text { display: none; }
    .profile-dropdown { right: -8px; }
    .modal-overlay { padding: 22px 12px; }
}
