/*
 * Marosoft License Hub – admin styles.
 *
 * 1. Tokens (light + dark)
 * 2. Base
 * 3. Layout: sidebar, topbar, content
 * 4. Page head, cards, grids
 * 5. Stats and chart
 * 6. Buttons, badges, alerts
 * 7. Forms and filters
 * 8. Tables, pager
 * 9. Timeline, products, misc
 * 10. Auth screens
 * 11. Responsive
 */

/* 1. Tokens ------------------------------------------------------------ */
:root {
    --bg: #f5f6fa;
    --surface: #ffffff;
    --surface-2: #f8f9fc;
    --border: #e4e7ef;
    --text: #161a2b;
    --muted: #697089;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-soft: #eef0ff;
    --success: #0f8a5f;
    --success-soft: #e6f6ef;
    --danger: #c42b3b;
    --danger-soft: #fdecee;
    --warning: #a35c00;
    --warning-soft: #fff4e0;
    --info: #1f6fb2;
    --info-soft: #e7f1fb;
    --sidebar: #12152a;
    --sidebar-text: #c3c7dc;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0d0f1a;
        --surface: #161a2b;
        --surface-2: #1b2035;
        --border: #272d45;
        --text: #e8eaf4;
        --muted: #9aa1bb;
        --primary: #7c74ff;
        --primary-hover: #918aff;
        --primary-soft: #23264a;
        --success: #3ccf91;
        --success-soft: #133326;
        --danger: #ff6b7a;
        --danger-soft: #3a1820;
        --warning: #ffb547;
        --warning-soft: #3a2a10;
        --info: #6bb4ff;
        --info-soft: #14283e;
        --sidebar: #0a0c16;
        --shadow: none;
        color-scheme: dark;
    }
}

/* 2. Base -------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.5 var(--font);
}

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

h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 650; }

code, .mono { font-family: var(--mono); font-size: .92em; }
code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: 1px 5px; }

hr { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }

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

.icon { width: 18px; height: 18px; flex: none; }

/* 3. Layout ------------------------------------------------------------ */
.app { display: flex; min-height: 100vh; }

.sidebar {
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    width: 240px;
    height: 100vh;
    padding: 18px 14px;
    background: var(--sidebar);
    color: var(--sidebar-text);
    flex: none;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; color: #fff; }
.brand:hover { text-decoration: none; }
.brand__mark {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: linear-gradient(135deg, #6366f1, #a855f7);
    color: #fff;
    font-weight: 800;
}
.brand__text { display: flex; flex-direction: column; line-height: 1.2; }
.brand__text small { color: var(--sidebar-text); font-size: 11px; opacity: .8; }
.brand--center { justify-content: center; color: var(--text); padding-bottom: 22px; }
.brand--center .brand__text small { color: var(--muted); }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav__item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: var(--radius-sm);
    color: var(--sidebar-text);
    font-weight: 500;
}
.nav__item:hover { background: rgba(255, 255, 255, .06); color: #fff; text-decoration: none; }
.nav__item.is-active { background: rgba(124, 116, 255, .18); color: #fff; }
.nav__item.is-active .icon { color: #a5a0ff; }

.sidebar__user {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: auto;
    padding-top: 14px;
    border-top: 1px solid rgba(255, 255, 255, .08);
}
.sidebar__account { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; color: #fff; }
.sidebar__account:hover { text-decoration: none; }
.sidebar__account span:last-child { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.sidebar__account strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.sidebar__account small { color: var(--sidebar-text); font-size: 11px; }
.avatar {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #2b3050;
    font-weight: 700;
    flex: none;
}

.icon-btn {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: inherit;
    cursor: pointer;
}
.icon-btn:hover { background: rgba(127, 127, 127, .15); }

.main { flex: 1; min-width: 0; }

.topbar { display: none; }

.content { max-width: 1180px; margin: 0 auto; padding: 28px 32px 60px; }

/* 4. Page head, cards, grids ----------------------------------------- */
.page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}
.page-head h1 { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; }
.page-head__actions { display: flex; gap: 8px; flex-wrap: wrap; }
.back { display: inline-block; margin-bottom: 6px; color: var(--muted); font-size: 13px; }

.card {
    margin-bottom: 20px;
    padding: 20px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}
.card--flush { padding: 0; overflow: hidden; }
.card--narrow { max-width: 720px; }
.card--highlight { border-color: var(--primary); background: var(--primary-soft); }
.card__title { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; font-size: 15px; font-weight: 650; }
.card__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card__head .card__title { margin: 0; }
.card__head--pad { margin: 0; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.card > p:first-of-type { margin-top: 0; }

.grid { display: grid; gap: 20px; }
.grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid > .card { margin-bottom: 0; }
.grid { margin-bottom: 20px; }

.empty { margin: 0; padding: 28px 20px; color: var(--muted); text-align: center; }
.empty-state { padding: 48px 20px; text-align: center; }
.empty-state .icon { width: 40px; height: 40px; color: var(--primary); }
.empty-state h2 { margin: 10px 0 6px; font-size: 17px; }

/* 5. Stats and chart -------------------------------------------------- */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 16px 18px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}
.stat__label { color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: .02em; text-transform: uppercase; }
.stat__value { font-size: 28px; font-weight: 700; letter-spacing: -.02em; }
.stat__hint { color: var(--muted); font-size: 12px; }
.stat--warn .stat__value { color: var(--danger); }

.chart { display: block; width: 100%; height: 160px; }
.chart__bar { fill: var(--primary); }
.chart__empty { fill: var(--border); }
.chart__axis { display: flex; justify-content: space-between; margin-top: 6px; color: var(--muted); font-size: 12px; }

/* 6. Buttons, badges, alerts ----------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 36px;
    padding: 7px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-weight: 550;
    white-space: nowrap;
    cursor: pointer;
    transition: background .15s, border-color .15s;
}
.btn:hover { border-color: var(--muted); text-decoration: none; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 1px;
}
.btn--primary { border-color: var(--primary); background: var(--primary); color: #fff; }
.btn--primary:hover { border-color: var(--primary-hover); background: var(--primary-hover); }
.btn--danger { border-color: var(--danger); background: transparent; color: var(--danger); }
.btn--danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn--ghost { border-color: transparent; background: transparent; }
.btn--small { min-height: 30px; padding: 4px 10px; font-size: 13px; }
.btn--block { width: 100%; }

.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.5;
    white-space: nowrap;
    vertical-align: middle;
}
.badge--success { background: var(--success-soft); color: var(--success); }
.badge--danger { background: var(--danger-soft); color: var(--danger); }
.badge--warning { background: var(--warning-soft); color: var(--warning); }
.badge--info { background: var(--info-soft); color: var(--info); }
.badge--muted, .badge--neutral { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }

.alert {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
    padding: 12px 14px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-weight: 500;
}
.alert--success { background: var(--success-soft); border-color: rgba(15, 138, 95, .25); color: var(--success); }
.alert--error { background: var(--danger-soft); border-color: rgba(196, 43, 59, .25); color: var(--danger); }
.alert--warning { background: var(--warning-soft); border-color: rgba(163, 92, 0, .25); color: var(--warning); }
.alert--info { background: var(--info-soft); border-color: rgba(31, 111, 178, .25); color: var(--info); }
.alert--link:hover { text-decoration: none; filter: brightness(.98); }

/* 7. Forms and filters ------------------------------------------------ */
.form { display: flex; flex-direction: column; gap: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-actions { display: flex; gap: 10px; }
.form > .btn { align-self: flex-start; }
.form > .btn--block { align-self: stretch; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field--wide { grid-column: 1 / -1; }
.field--short { max-width: 260px; }
.field__label { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 13px; }
.field__help { color: var(--muted); font-size: 12.5px; }
.field__error { color: var(--danger); font-size: 12.5px; font-weight: 600; }
.has-error input, .has-error select { border-color: var(--danger); }

input[type="text"], input[type="email"], input[type="password"], input[type="url"], input[type="number"],
input[type="date"], input[type="search"], input[type="file"], select, textarea {
    width: 100%;
    min-height: 38px;
    padding: 8px 11px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: inherit;
}
textarea { min-height: 90px; resize: vertical; }
input[type="file"] { padding: 6px; background: var(--surface-2); }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .8; }

.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--primary); }
.check--small { font-size: 13px; color: var(--muted); }

.inline-form { display: flex; gap: 8px; align-items: center; }
.inline-form input[type="text"] { max-width: 280px; }
.inline-form select { width: auto; min-height: 32px; padding: 4px 8px; }

.filters { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.filters select { width: auto; min-width: 150px; }
.filters__search { position: relative; flex: 1 1 260px; }
.filters__search .icon { position: absolute; top: 10px; left: 11px; color: var(--muted); }
.filters__search input { padding-left: 36px; }

/* 8. Tables, pager ---------------------------------------------------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; }
.table th {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: .02em;
    text-align: left;
    text-transform: uppercase;
    white-space: nowrap;
}
.table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.card:not(.card--flush) .table th:first-child, .card:not(.card--flush) .table td:first-child { padding-left: 0; }
.card:not(.card--flush) .table th { background: transparent; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { text-align: right; white-space: nowrap; }
.table .actions form, .table .actions a { display: inline-flex; gap: 6px; margin-left: 4px; }
.sub { margin-top: 2px; color: var(--muted); font-size: 12px; }
.sub-list { color: var(--muted); font-size: 13px; }

.pager { display: flex; align-items: center; justify-content: flex-end; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--border); }
.pager .muted { margin-right: auto; }
.pager__pos { color: var(--muted); font-size: 13px; }

/* 9. Timeline, products, misc ---------------------------------------- */
.timeline { margin: 0; padding: 0; list-style: none; }
.timeline__item {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 10px 0 10px 16px;
    border-bottom: 1px solid var(--border);
    position: relative;
}
.timeline__item:last-child { border-bottom: 0; }
.timeline__item::before {
    content: "";
    position: absolute;
    top: 17px;
    left: 0;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--muted);
}
.timeline__item--success::before { background: var(--success); }
.timeline__item--danger::before { background: var(--danger); }
.timeline__main { display: flex; flex-direction: column; min-width: 0; }
.timeline__type { font-weight: 600; }
.timeline__msg { color: var(--muted); overflow-wrap: anywhere; }
.timeline__meta { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px 10px; color: var(--muted); font-size: 12px; text-align: right; flex: none; max-width: 45%; }

.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 20px; }
.product-grid .card { margin: 0; }
.product { display: flex; flex-direction: column; gap: 16px; }
.product__head { display: flex; justify-content: space-between; gap: 10px; }
.product__name { font-size: 16px; font-weight: 650; }
.product__slug { display: inline-block; margin-top: 4px; }
.product__facts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; margin: 0; }
.product__facts dt { color: var(--muted); font-size: 12px; }
.product__facts dd { margin: 0; font-weight: 550; }
.product__stats { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.product__stats a { display: flex; flex-direction: column; align-items: center; padding: 10px 6px; color: var(--text); }
.product__stats a + a { border-left: 1px solid var(--border); }
.product__stats a:hover { background: var(--surface-2); text-decoration: none; }
.product__stats strong { font-size: 18px; }
.product__stats span { color: var(--muted); font-size: 12px; }
.product__actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: auto; }

.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 20px; margin: 0; }
.facts dt { color: var(--muted); font-size: 12px; }
.facts dd { margin: 2px 0 0; font-weight: 550; }

.codebox {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 20px;
    padding: 12px 14px;
    border: 1px dashed var(--primary);
    border-radius: var(--radius-sm);
    background: var(--surface);
}
.codebox code { border: 0; background: none; padding: 0; font-size: 15px; font-weight: 600; overflow-wrap: anywhere; }
.card--highlight .codebox { margin-bottom: 0; }

/* 10. Auth screens ---------------------------------------------------- */
.auth { display: grid; place-items: center; min-height: 100vh; padding: 24px 16px; }
.auth__box { width: 100%; max-width: 400px; }
.auth .card { padding: 28px; }
.auth .card__title { font-size: 19px; }

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

@media (max-width: 860px) {
    .app { display: block; }
    .sidebar {
        position: fixed;
        z-index: 20;
        left: 0;
        transform: translateX(-100%);
        transition: transform .2s ease;
    }
    .nav-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .35); }
    .table { min-width: 640px; }
    .table td { white-space: nowrap; }
    .topbar {
        position: sticky;
        top: 0;
        z-index: 10;
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 8px 12px;
        border-bottom: 1px solid var(--border);
        background: var(--surface);
    }
    .topbar__title { font-weight: 650; }
    .content { padding: 20px 16px 48px; }
    .form-grid, .form-grid--3, .facts, .product__facts { grid-template-columns: 1fr; }
    .product-grid { grid-template-columns: 1fr; }
    .timeline__item { flex-direction: column; gap: 4px; }
    .timeline__meta { justify-content: flex-start; max-width: none; text-align: left; }
    .inline-form { flex-wrap: wrap; }
    .filters select { flex: 1 1 140px; }
}

@media (max-width: 480px) {
    .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
    .stat { padding: 12px; }
    .stat__value { font-size: 22px; }
    .page-head__actions, .page-head > .btn { width: 100%; }
    .page-head__actions form, .page-head__actions .btn, .page-head > .btn { flex: 1; width: 100%; }
}
