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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    color: #1a1a2e;
    background: #f5f6fa;
    display: flex;
    min-height: 100vh;
}

a { color: #4361ee; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout ─────────────────────────────────────────────────── */
.layout { display: flex; width: 100%; }

/* ── Sidebar nav ────────────────────────────────────────────── */
.sidebar {
    width: 220px;
    min-height: 100vh;
    background: #1a1a2e;
    color: #c8cfe8;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow: hidden;
    transition: width 0.22s ease;
}

.sidebar.collapsed { width: 52px; }

.sidebar-brand {
    padding: 18px 14px;
    font-size: 16px;
    font-weight: 700;
    color: #fff;
    border-bottom: 1px solid #2d2d4e;
    letter-spacing: 0.3px;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    flex-shrink: 0;
}
.sidebar-brand:hover { background: #2d2d4e; }

.sidebar-logo { height: 26px; width: auto; flex-shrink: 0; }

.sidebar-nav { padding: 12px 0; flex: 1; }

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    color: #c8cfe8;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
    overflow: hidden;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
    background: #2d2d4e;
    color: #fff;
    text-decoration: none;
}

.nav-icon { font-size: 16px; flex-shrink: 0; width: 20px; text-align: center; }
.nav-label { white-space: nowrap; }
.sidebar.collapsed .nav-label { display: none; }
.sidebar.collapsed .sidebar-brand-text { display: none; }
.sidebar.collapsed .sidebar-nav a { padding: 10px 0; justify-content: center; gap: 0; }

/* Floating tooltip for collapsed nav */
#nav-tooltip {
    display: none;
    position: fixed;
    background: rgba(26, 26, 46, 0.95);
    color: #fff;
    padding: 5px 11px;
    border-radius: 5px;
    font-size: 13px;
    font-weight: 500;
    pointer-events: none;
    z-index: 500;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

/* ── Main content ───────────────────────────────────────────── */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

/* ── Header ─────────────────────────────────────────────────── */
.header {
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
    padding: 0 28px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.header-title { font-size: 15px; font-weight: 600; color: #1a1a2e; }

.header-user { display: flex; align-items: center; gap: 14px; color: #64748b; font-size: 13px; }

/* ── Page body ──────────────────────────────────────────────── */
.content { padding: 28px; }

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.page-title { font-size: 20px; font-weight: 700; color: #1a1a2e; }

/* ── Flash messages ─────────────────────────────────────────── */
.flashes { list-style: none; margin-bottom: 20px; }

.flash {
    padding: 10px 16px;
    border-radius: 6px;
    margin-bottom: 8px;
    font-size: 13px;
    font-weight: 500;
}

.flash.success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.flash.error   { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.flash.info    { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 16px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: opacity 0.15s;
    text-decoration: none;
    white-space: nowrap;
}

.btn:hover { opacity: 0.85; text-decoration: none; }

.btn-primary   { background: #4361ee; color: #fff; }
.btn-secondary { background: #e2e8f0; color: #1a1a2e; }
.btn-danger    { background: #ef4444; color: #fff; }
.btn-warning   { background: #f59e0b; color: #fff; }
.btn-sm        { padding: 4px 10px; font-size: 12px; }

/* ── Tables ─────────────────────────────────────────────────── */
.card {
    background: #fff;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
    overflow: visible;
}

/* Preserve rounded corners on the table without overflow:hidden */
.card table { border-collapse: separate; border-spacing: 0; }
.card thead tr:first-child th:first-child { border-radius: 10px 0 0 0; }
.card thead tr:first-child th:last-child  { border-radius: 0 10px 0 0; }
.card tbody tr:last-child td:first-child  { border-radius: 0 0 0 10px; }
.card tbody tr:last-child td:last-child   { border-radius: 0 0 10px 0; }

table { width: 100%; border-collapse: collapse; }

thead { background: #f8fafc; }

th.sortable { cursor: pointer; white-space: nowrap; }
th.sortable:hover { background: #f1f5f9; }
.sort-ind { font-size: 10px; color: #94a3b8; margin-left: 2px; }

th {
    padding: 10px 16px;
    text-align: left;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: #64748b;
    border-bottom: 1px solid #e2e8f0;
}

td {
    padding: 12px 16px;
    border-bottom: 1px solid #f1f5f9;
    color: #334155;
    vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fafc; }

/* ── Badges ─────────────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    text-transform: capitalize;
}

.badge-admin    { background: #e0e7ff; color: #3730a3; }
.badge-agent    { background: #f0fdf4; color: #166534; }

/* ── Status pills ───────────────────────────────────────────── */
.pill {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}

.pill-draft   { background: #fed7aa; color: #9a3412; }
.pill-active  { background: #dcfce7; color: #166534; }
.pill-legacy  { background: #e5e7eb; color: #6b7280; }
.badge-active   { background: #dcfce7; color: #166534; }
.badge-inactive { background: #fee2e2; color: #991b1b; }
.badge-default     { background: #e0e7ff; color: #3730a3; }
.badge-processing  { background: #dbeafe; color: #1e40af; }
.badge-completed   { background: #dcfce7; color: #166534; }
.badge-failed      { background: #fee2e2; color: #991b1b; }

/* ── Forms ──────────────────────────────────────────────────── */
.form-card {
    background: #fff;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
    padding: 28px;
    max-width: 480px;
}

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

label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #374151;
    margin-bottom: 6px;
}

input[type="text"],
input[type="email"],
input[type="password"],
select,
textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 14px;
    color: #1a1a2e;
    background: #fff;
    transition: border-color 0.15s, box-shadow 0.15s;
    outline: none;
}

input:focus, select:focus {
    border-color: #4361ee;
    box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.12);
}

.form-actions { display: flex; gap: 10px; margin-top: 24px; }

/* ── Login page ─────────────────────────────────────────────── */
.login-page {
    width: 100%;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f5f6fa;
}

.login-card {
    background: #fff;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    padding: 48px 52px;
    width: 100%;
    max-width: 520px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.06);
}

.login-title {
    font-size: 22px;
    font-weight: 700;
    color: #1a1a2e;
    margin-bottom: 6px;
}

.login-subtitle {
    font-size: 13px;
    color: #64748b;
    margin-bottom: 28px;
}

.login-card .btn-primary { width: 100%; justify-content: center; padding: 10px; font-size: 14px; }

/* ── Disabled button ────────────────────────────────────────── */
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }

/* ── Token count cell ───────────────────────────────────────── */
.token-count {
    font-variant-numeric: tabular-nums;
    font-size: 13px;
    color: #475569;
    cursor: default;
    border-bottom: 1px dashed #94a3b8;
}

/* ── Toggle switch ──────────────────────────────────────────── */
.toggle-switch {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
}

.toggle-switch input { display: none; }

.toggle-track {
    width: 36px;
    height: 20px;
    background: #cbd5e1;
    border-radius: 999px;
    position: relative;
    transition: background 0.2s;
    flex-shrink: 0;
}

.toggle-track::after {
    content: '';
    position: absolute;
    width: 14px;
    height: 14px;
    background: #fff;
    border-radius: 50%;
    top: 3px;
    left: 3px;
    transition: transform 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.toggle-switch input:checked + .toggle-track { background: #4361ee; }
.toggle-switch input:checked + .toggle-track::after { transform: translateX(16px); }

.toggle-label { font-size: 13px; font-weight: 500; color: #475569; }

/* ── Overflow menu ──────────────────────────────────────────── */
.overflow-menu { position: relative; display: inline-block; }

.overflow-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    padding: 2px 7px;
    border-radius: 4px;
    color: #64748b;
}
.overflow-btn:hover { background: #f1f5f9; color: #1a1a2e; }

.overflow-dropdown {
    display: none;
    position: fixed;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.10);
    min-width: 160px;
    z-index: 200;
}

.overflow-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 9px 14px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 13px;
    color: #334155;
    white-space: nowrap;
}
.overflow-item:hover { background: #f8fafc; }

.overflow-item-disabled {
    color: #cbd5e1 !important;
    cursor: not-allowed;
}
.overflow-item-disabled:hover { background: none; }

/* ── Edit Modal ─────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 1000;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    overflow-y: auto;
    padding: 24px 16px;
}

.modal-container {
    background: #fff;
    border-radius: 12px;
    width: 100%;
    max-width: 1400px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.18);
    display: flex;
    flex-direction: column;
}

.modal-body {
    display: flex;
    min-height: 0;
}

.modal-left {
    flex: 0 0 65%;
    padding: 32px 28px 28px 32px;
    border-right: 1px solid #e2e8f0;
}

.modal-right {
    flex: 0 0 35%;
    padding: 32px 32px 28px 28px;
}

.modal-section-title {
    font-size: 15px;
    font-weight: 700;
    color: #1a1a2e;
    margin-bottom: 20px;
}

.modal-textarea {
    resize: none;
    overflow-y: auto;
    font-family: inherit;
    line-height: 1.5;
}

.modal-readonly-group { margin-top: 24px; padding-top: 20px; border-top: 1px solid #e2e8f0; }

.readonly-field {
    padding: 8px 12px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 14px;
    color: #64748b;
    min-height: 36px;
}

.modal-footer {
    display: flex;
    gap: 10px;
    padding: 20px 32px;
    border-top: 1px solid #e2e8f0;
    background: #f8fafc;
    border-radius: 0 0 12px 12px;
}
