/* ============================================================
   Design tokens — change colors & fonts here only.
   ============================================================ */
:root {
    /* Fonts */
    --font-main: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

    /* Brand (Upwork-style green) */
    --color-primary: #14a800;
    --color-primary-hover: #108a00;
    --color-primary-soft: #e6f5e3;

    /* Surfaces */
    --color-bg: #f7f7f0;          /* cream page background */
    --color-surface: #ffffff;      /* cards, table */
    --color-surface-alt: #fbfbf5;  /* subtle rows / inputs */

    /* Text */
    --color-text: #0d1f13;
    --color-muted: #5f7268;
    --color-heading: #001e00;

    /* Lines & states */
    --color-border: #e6e7e0;
    --color-border-strong: #d5d7cd;
    --color-danger: #d7263d;
    --color-danger-hover: #b71e31;
    --color-danger-soft: #fdecee;
    --color-warning: #b7791f;
    --color-warning-soft: #fbf3e2;
    --color-neutral-soft: #eef0ec;

    /* Shape */
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 2px rgba(0, 30, 0, .04), 0 8px 24px rgba(0, 30, 0, .05);
    --gutter: 24px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: var(--font-main);
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

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

/* ---------- Top bar ---------- */
.topbar {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    position: sticky;
    top: 0;
    z-index: 10;
}
.topbar-inner {
    max-width: 1120px;
    margin: 0 auto;
    padding: 0 var(--gutter);
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 800;
    font-size: 20px;
    color: var(--color-heading);
    letter-spacing: -.3px;
}
.brand-dot {
    width: 26px; height: 26px;
    border-radius: 50%;
    background: var(--color-primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 15px;
    font-weight: 800;
}
.topbar-right { display: flex; align-items: center; gap: 16px; }
.topbar-user { color: var(--color-muted); font-weight: 600; font-size: 14px; }

/* ---------- Layout ---------- */
.container {
    max-width: 1120px;
    margin: 0 auto;
    padding: var(--gutter);
}
.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}
.page-title { font-size: 24px; font-weight: 800; color: var(--color-heading); margin: 0; letter-spacing: -.4px; }
.page-actions { display: flex; gap: 12px; align-items: center; }
.search-form { display: flex; gap: 8px; }
.search-input { width: 300px; max-width: 100%; }

/* ---------- Stat cards ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.stat {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow);
}
.stat-value { font-size: 28px; font-weight: 800; color: var(--color-heading); line-height: 1; }
.stat-label { margin-top: 8px; color: var(--color-muted); font-size: 13px; font-weight: 600; }

/* ---------- Card ---------- */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.card-pad { padding: 24px; }

/* ---------- Table ---------- */
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
    text-align: left;
    font-size: 12px;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--color-muted);
    font-weight: 700;
    padding: 14px 18px;
    background: var(--color-surface-alt);
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
}
tbody td {
    padding: 14px 18px;
    border-bottom: 1px solid var(--color-border);
    vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--color-surface-alt); }
thead th:first-child, tbody td.key { width: 100%; }
thead th:last-child, tbody td[data-label="Actions"] { min-width: 300px; }
.key { font-weight: 700; color: var(--color-heading); letter-spacing: .3px; }
.key-copy {
    display: inline;
    cursor: pointer;
    border-radius: 6px;
    transition: color .15s;
    outline: none;
}
.key-copy:hover { color: var(--color-primary); }
.key-copy:focus-visible { box-shadow: 0 0 0 3px var(--color-primary-soft); }
.key-copy:active { opacity: .7; }
.copy-ico {
    width: 15px;
    height: 15px;
    color: var(--color-muted);
    display: inline-block;
    vertical-align: middle;
    margin-left: 7px;
    transition: color .15s;
}
.key-copy:hover .copy-ico { color: var(--color-primary); }
.muted { color: var(--color-muted); }
.nowrap { white-space: nowrap; }

/* ---------- Badges ---------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 999px;
    line-height: 1.4;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge-active { color: var(--color-primary); background: var(--color-primary-soft); }
.badge-expired { color: var(--color-danger); background: var(--color-danger-soft); }
.badge-disabled { color: var(--color-muted); background: var(--color-neutral-soft); }
.badge-locked { color: var(--color-warning); background: var(--color-warning-soft); }
.badge-open { color: var(--color-muted); background: var(--color-neutral-soft); }
.badge-plain { color: var(--color-muted); background: var(--color-neutral-soft); }
.badge-plain::before { display: none; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 700;
    padding: 10px 18px;
    border-radius: 999px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background .15s, border-color .15s, color .15s;
    white-space: nowrap;
    line-height: 1;
}
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-hover); color: #fff; }
.btn-outline { background: var(--color-surface); color: var(--color-heading); border-color: var(--color-border-strong); }
.btn-outline:hover { border-color: var(--color-primary); color: var(--color-primary); }
.btn-danger-outline { background: var(--color-surface); color: var(--color-danger); border-color: var(--color-border-strong); }
.btn-danger-outline:hover { border-color: var(--color-danger); background: var(--color-danger-soft); }
.btn-block { width: 100%; justify-content: center; }
.btn-sm { padding: 7px 12px; font-size: 13px; }

/* row actions */
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.field { display: flex; flex-direction: column; gap: 7px; }
.field.full { grid-column: 1 / -1; }
label { font-size: 13px; font-weight: 700; color: var(--color-heading); }
.input, select.input {
    font-family: inherit;
    font-size: 15px;
    padding: 12px 14px;
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    color: var(--color-text);
    width: 100%;
    transition: border-color .15s, box-shadow .15s;
}
.input:focus, select.input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-soft);
}
.input-group { display: flex; gap: 10px; }
.input-group .input { flex: 1; }
.pills { display: flex; flex-wrap: wrap; gap: 8px; }
.pill {
    font-family: inherit;
    font-size: 13px;
    font-weight: 700;
    padding: 7px 13px;
    border-radius: 999px;
    border: 1px solid var(--color-border-strong);
    background: var(--color-surface);
    color: var(--color-heading);
    cursor: pointer;
    transition: background .15s, border-color .15s, color .15s;
}
.pill:hover { border-color: var(--color-primary); color: var(--color-primary); background: var(--color-primary-soft); }
.checkbox-row { display: flex; align-items: center; gap: 10px; }
.checkbox-row input { width: 18px; height: 18px; accent-color: var(--color-primary); }
.checkbox-row label { font-weight: 600; color: var(--color-text); }
.form-actions { display: flex; gap: 12px; margin-top: 4px; }

/* ---------- Flash ---------- */
.flash {
    padding: 13px 18px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 20px;
    border: 1px solid transparent;
}
.flash-success { background: var(--color-primary-soft); color: var(--color-primary-hover); border-color: #c7e8c1; }
.flash-error { background: var(--color-danger-soft); color: var(--color-danger-hover); border-color: #f4c7ce; }

/* ---------- Toast ---------- */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(12px);
    background: var(--color-heading);
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    padding: 10px 20px;
    border-radius: 999px;
    box-shadow: 0 8px 24px rgba(0, 30, 0, .18);
    opacity: 0;
    pointer-events: none;
    transition: opacity .18s, transform .18s;
    z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Modal ---------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 20, 0, .45);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 200;
}
.modal {
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: 0 20px 60px rgba(0, 30, 0, .25);
    width: 100%;
    max-width: 440px;
    overflow: hidden;
}
.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--color-border);
}
.modal-title {
    font-size: 15px;
    font-weight: 800;
    color: var(--color-heading);
    letter-spacing: .2px;
    word-break: break-all;
}
.modal-close {
    border: none;
    background: transparent;
    font-size: 26px;
    line-height: 1;
    color: var(--color-muted);
    cursor: pointer;
    padding: 0 4px;
    border-radius: 6px;
}
.modal-close:hover { color: var(--color-heading); }
.modal-body {
    padding: 20px;
    color: var(--color-text);
    font-size: 15px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 60vh;
    overflow-y: auto;
}

/* ---------- Empty ---------- */
.empty { padding: 60px 24px; text-align: center; color: var(--color-muted); }
.empty-icon { font-size: 34px; margin-bottom: 8px; }

/* ---------- Login ---------- */
.auth-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 36px 32px;
}
.auth-brand { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 26px; }
.auth-brand .brand-dot { width: 34px; height: 34px; font-size: 18px; }
.auth-brand span { font-size: 24px; font-weight: 800; color: var(--color-heading); }
.auth-card .field { margin-bottom: 16px; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
    .stats { grid-template-columns: repeat(2, 1fr); }
    .form-grid { grid-template-columns: 1fr; }
}

@media (max-width: 680px) {
    :root { --gutter: 16px; }

    .topbar-inner { height: 56px; }
    .brand { font-size: 18px; }

    .stat { padding: 14px 16px; }
    .stat-value { font-size: 24px; }

    /* header + actions stack and go full width */
    .page-head { flex-direction: column; align-items: stretch; gap: 14px; }
    .page-title { font-size: 21px; }
    .page-actions { width: 100%; flex-direction: column; align-items: stretch; }
    .search-form { width: 100%; }
    .search-input { width: auto; flex: 1; }
    .search-form .btn { flex: 0 0 auto; }
    .page-actions > .btn { width: 100%; justify-content: center; }

    /* table -> stacked cards */
    .table-wrap { overflow-x: visible; }
    table, thead, tbody, tr, th, td { display: block; width: 100%; }
    thead { display: none; }
    tbody tr {
        border: 1px solid var(--color-border);
        border-radius: var(--radius);
        background: var(--color-surface);
        box-shadow: var(--shadow);
        margin-bottom: 14px;
        overflow: hidden;
    }
    tbody tr:last-child { margin-bottom: 0; }
    tbody tr:hover { background: var(--color-surface); }
    tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 16px;
        text-align: right;
        padding: 12px 16px;
        border: none;
        border-bottom: 1px solid var(--color-border);
    }
    tbody td:last-child { border-bottom: none; }
    tbody td::before {
        content: attr(data-label);
        font-size: 11px;
        font-weight: 700;
        letter-spacing: .04em;
        text-transform: uppercase;
        color: var(--color-muted);
        text-align: left;
        flex: 0 0 auto;
    }
    td.key { font-size: 16px; }

    /* actions become a full-width stacked group */
    td[data-label="Actions"] { flex-direction: column; align-items: stretch; gap: 10px; min-width: 0; }
    tbody td.key { width: auto; }
    .row-actions { flex-direction: row; flex-wrap: wrap; align-items: stretch; gap: 8px; width: 100%; justify-content: flex-start; }
    .row-actions > * { flex: 1 1 calc(50% - 4px); width: auto; }
    .row-actions form { display: flex; }
    .row-actions form .btn { width: 100%; }
    .row-actions .btn { justify-content: center; }
    .row-actions .btn-sm { padding: 11px 12px; font-size: 14px; }

    /* forms */
    .card-pad { padding: 18px; }
    .form-actions { flex-direction: column; }
    .form-actions .btn { width: 100%; justify-content: center; }
    .input-group { flex-direction: column; }
    .input-group .btn { width: 100%; justify-content: center; }
}

@media (max-width: 400px) {
    .stats { grid-template-columns: 1fr 1fr; gap: 12px; }
    .topbar-user { display: none; }
}
