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

/* ── Base ── */
body {
    font-family: 'Sarabun', system-ui, sans-serif;
    background: #f5f6f8;
    color: #1a1d23;
    -webkit-font-smoothing: antialiased;
    font-size: 15px;
}

/* ─────────────────────────────────────
   Sidebar
───────────────────────────────────── */
.sidebar {
    width: 220px;
    background: #1a1d23;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.brand {
    padding: 20px 18px 18px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    display: flex;
    align-items: center;
    gap: 10px;
}

/* ── Tenant Switcher ── */
.tenant-switcher-wrap {
    position: relative;
    padding: 12px 10px;
    border-bottom: 1px solid rgba(255,255,255,0.07);
}

.tenant-trigger {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    text-align: left;
    font-family: 'Sarabun', sans-serif;
}

.tenant-trigger:hover,
.tenant-trigger--open {
    background: rgba(255,255,255,0.09);
    border-color: rgba(255,255,255,0.15);
}

.tenant-trigger-icon {
    width: 30px;
    height: 30px;
    background: #22c97a;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.tenant-trigger-text {
    flex: 1;
    min-width: 0;
}

.tenant-trigger-label {
    display: block;
    font-size: 0.62rem;
    color: rgba(255,255,255,0.3);
    letter-spacing: 0.04em;
    line-height: 1;
    margin-bottom: 3px;
}

.tenant-trigger-name {
    display: block;
    font-size: 0.82rem;
    font-weight: 700;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
}

.tenant-trigger-chevron {
    flex-shrink: 0;
    color: rgba(255,255,255,0.3);
    transition: transform 0.2s;
}

.tenant-trigger--open .tenant-trigger-chevron {
    transform: rotate(180deg);
}

.tenant-dropdown {
    position: absolute;
    left: 10px;
    right: 10px;
    top: calc(100% - 4px);
    background: #22252e;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 10px;
    box-shadow: 0 12px 32px rgba(0,0,0,0.4);
    z-index: 100;
    overflow: hidden;
    padding: 6px;
}

.tenant-dropdown-header {
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: rgba(255,255,255,0.25);
    padding: 6px 10px 8px;
}

.tenant-dropdown-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 10px;
    border-radius: 7px;
    font-size: 0.83rem;
    font-weight: 500;
    color: rgba(255,255,255,0.7);
    background: none;
    border: none;
    cursor: pointer;
    font-family: 'Sarabun', sans-serif;
    text-align: left;
    transition: background 0.1s, color 0.1s;
    text-decoration: none;
}

.tenant-dropdown-item:hover {
    background: rgba(255,255,255,0.07);
    color: #fff;
}

.tenant-dropdown-item--active {
    background: rgba(34,201,122,0.12);
    color: #22c97a;
    font-weight: 700;
}

.tenant-active-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #22c97a;
    flex-shrink: 0;
    box-shadow: 0 0 6px rgba(34,201,122,0.6);
}

.tenant-inactive-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    flex-shrink: 0;
}

.brand-icon {
    width: 32px;
    height: 32px;
    background: #22c97a;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.brand-name {
    font-size: 0.9rem;
    font-weight: 700;
    color: #fff;
    line-height: 1.2;
}

.brand-sub {
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.35);
    margin-top: 1px;
}

.user-badge {
    margin: 14px 12px;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-avatar {
    width: 30px;
    height: 30px;
    background: #2d3240;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 0.75rem;
    font-weight: 700;
    color: #22c97a;
}

.user-name {
    font-size: 0.8rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.85);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-section-label {
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.25);
    padding: 12px 18px 6px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    margin: 1px 8px;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.5);
    text-decoration: none;
    transition: background 0.12s, color 0.12s;
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.06);
    color: rgba(255, 255, 255, 0.85);
}

.nav-link.active {
    background: rgba(34, 201, 122, 0.15);
    color: #22c97a;
}

.nav-link svg {
    width: 17px;
    height: 17px;
    flex-shrink: 0;
    stroke: currentColor;
}

.sidebar-footer {
    margin-top: auto;
    padding: 14px 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.07);
}

/* ─────────────────────────────────────
   Layout shell
───────────────────────────────────── */
.app-shell {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

.main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ─────────────────────────────────────
   Topbar
───────────────────────────────────── */
.topbar {
    height: 56px;
    background: #fff;
    border-bottom: 1px solid #e8eaed;
    display: flex;
    align-items: center;
    padding: 0 24px;
    flex-shrink: 0;
}

.page-title {
    font-size: 1rem;
    font-weight: 700;
    color: #1a1d23;
}

.page-date {
    font-size: 0.75rem;
    color: #9099a8;
    font-family: 'IBM Plex Mono', monospace;
    margin-left: 12px;
}

/* ─────────────────────────────────────
   Main content
───────────────────────────────────── */
.main-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

/* ─────────────────────────────────────
   Toast
───────────────────────────────────── */
.toast {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: #edfaf3;
    border: 1px solid #b7edcf;
    border-radius: 10px;
    font-size: 0.875rem;
    color: #137a42;
    margin-bottom: 20px;
}

.toast-error {
    background: #fef2f2;
    border-color: #fecaca;
    color: #b91c1c;
}

/* ─────────────────────────────────────
   Card
───────────────────────────────────── */
.card {
    background: #fff;
    border-radius: 12px;
    border: 1px solid #e8eaed;
}

/* ─────────────────────────────────────
   Buttons
───────────────────────────────────── */
.btn-primary {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 18px;
    background: #1a1d23;
    color: #fff;
    font-size: 0.875rem;
    font-weight: 600;
    border-radius: 9px;
    border: none;
    cursor: pointer;
    transition: background 0.12s;
    font-family: 'Sarabun', sans-serif;
    text-decoration: none;
}

.btn-primary:hover { background: #2d3240; }

.btn-ghost {
    display: inline-flex;
    align-items: center;
    padding: 9px 16px;
    background: transparent;
    color: #6b7280;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: 9px;
    border: 1px solid #e8eaed;
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
    font-family: 'Sarabun', sans-serif;
}

.btn-ghost:hover {
    background: #f5f6f8;
    color: #1a1d23;
}

/* ─────────────────────────────────────
   Badges
───────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-green  { background: #edfaf3; color: #137a42; }
.badge-gray   { background: #f3f4f6; color: #6b7280; }
.badge-purple { background: #f3f0ff; color: #6d28d9; }
.badge-blue   { background: #eff6ff; color: #1d4ed8; }

/* ─────────────────────────────────────
   Data table
───────────────────────────────────── */
.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th {
    text-align: left;
    padding: 11px 16px;
    font-size: 0.75rem;
    font-weight: 600;
    color: #9099a8;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    background: #f9fafb;
    border-bottom: 1px solid #e8eaed;
}

.data-table td {
    padding: 13px 16px;
    font-size: 0.9rem;
    color: #374151;
    border-bottom: 1px solid #f3f4f6;
    vertical-align: middle;
}

.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: #fafbfc; }

.data-table .mono {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.8rem;
    color: #6b7280;
}

.data-table .strong {
    font-weight: 600;
    color: #1a1d23;
}

.action-link {
    font-size: 0.8rem;
    font-weight: 600;
    color: #4b5563;
    background: none;
    border: none;
    cursor: pointer;
    padding: 5px 10px;
    border-radius: 6px;
    transition: background 0.1s, color 0.1s;
    font-family: 'Sarabun', sans-serif;
}

/* ─────────────────────────────────────
   Pagination
───────────────────────────────────── */
.pagination-wrap {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 16px;
}

.pagination-summary {
    color: #9099a8;
    font-size: 0.82rem;
    font-weight: 600;
}

.pagination-links {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.pagination-btn {
    min-width: 34px;
    height: 34px;
    padding: 0 11px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #e8eaed;
    border-radius: 8px;
    background: #fff;
    color: #4b5563;
    font-size: 0.82rem;
    font-weight: 700;
    text-decoration: none;
}

.pagination-btn:hover {
    border-color: #1a1d23;
    color: #1a1d23;
}

.pagination-btn--active {
    background: #1a1d23;
    border-color: #1a1d23;
    color: #fff;
}

.pagination-btn--disabled {
    background: #f5f6f8;
    color: #c0c4cc;
    cursor: default;
}

.action-link:hover { background: #f3f4f6; color: #1a1d23; }
.action-link.danger:hover { background: #fef2f2; color: #dc2626; }

/* ─────────────────────────────────────
   Modal
───────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(2px);
}

.modal-box {
    background: #fff;
    border-radius: 16px;
    width: 100%;
    max-width: 440px;
    margin: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
    overflow: hidden;
}

.modal-header { padding: 20px 24px 0; }

.modal-title {
    font-size: 1rem;
    font-weight: 700;
    color: #1a1d23;
}

.modal-body {
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid #f3f4f6;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* ─────────────────────────────────────
   Form elements
───────────────────────────────────── */
.form-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: #4b5563;
    margin-bottom: 6px;
}

.form-label .req { color: #ef4444; }

.form-input {
    width: 100%;
    padding: 10px 13px;
    border: 1.5px solid #e8eaed;
    border-radius: 9px;
    font-size: 0.9rem;
    font-family: 'Sarabun', sans-serif;
    color: #1a1d23;
    background: #fff;
    transition: border-color 0.12s;
    outline: none;
}

.form-input:focus { border-color: #1a1d23; }
.form-input[readonly] { background: #f9fafb; color: #9099a8; }

.sr-only-file {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.upload-box {
    display: grid;
    grid-template-columns: 56px 1fr auto;
    align-items: center;
    gap: 12px;
    min-height: 72px;
    padding: 10px 12px;
    border: 1.5px dashed #d7dbe2;
    border-radius: 10px;
    background: #fbfcfd;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}

.upload-box:hover {
    border-color: #1a1d23;
    background: #fff;
}

.upload-preview {
    width: 52px;
    height: 52px;
    border-radius: 9px;
    background: #f0f2f5;
    color: #9ca3af;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
}

.upload-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.upload-title {
    font-size: 0.86rem;
    font-weight: 700;
    color: #1a1d23;
}

.upload-subtitle {
    font-size: 0.74rem;
    color: #9099a8;
    margin-top: 2px;
}

.upload-action {
    height: 34px;
    padding: 0 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: #1a1d23;
    color: #fff;
    font-size: 0.78rem;
    font-weight: 800;
    white-space: nowrap;
}

.form-select {
    width: 100%;
    padding: 10px 13px;
    border: 1.5px solid #e8eaed;
    border-radius: 9px;
    font-size: 0.9rem;
    font-family: 'Sarabun', sans-serif;
    color: #1a1d23;
    background: #fff;
    outline: none;
    cursor: pointer;
    transition: border-color 0.12s;
}

.form-select:focus { border-color: #1a1d23; }

/* ─────────────────────────────────────
   Dashboard
───────────────────────────────────── */
.dashboard-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

.stat-card {
    padding: 24px;
}

.stat-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: #9099a8;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 10px;
}

.stat-value {
    font-size: 2.25rem;
    font-weight: 700;
    color: #1a1d23;
    font-family: 'IBM Plex Mono', monospace;
    line-height: 1;
}

.stat-link {
    display: inline-block;
    margin-top: 12px;
    font-size: 0.8rem;
    font-weight: 600;
    color: #22c97a;
    text-decoration: none;
}

.stat-link:hover { text-decoration: underline; }

.welcome-card {
    padding: 24px;
}

.welcome-name {
    font-size: 1.1rem;
    font-weight: 700;
    color: #1a1d23;
    margin-top: 4px;
}

.welcome-sub {
    font-size: 0.875rem;
    color: #6b7280;
    margin-top: 4px;
}

/* ─────────────────────────────────────
   Misc
───────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: #9099a8;
    font-size: 0.9rem;
}

[x-cloak] { display: none !important; }
