:root {
    --bg: #f5f7fb;
    --panel: #ffffff;
    --ink: #172033;
    --muted: #647084;
    --line: #d9e0ea;
    --primary: #146c94;
    --primary-dark: #0f526f;
    --accent: #2f8f5b;
    --danger: #b42318;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    display: grid;
    grid-template-columns: 248px 1fr;
    background: var(--bg);
    color: var(--ink);
    font-family: Arial, Helvetica, sans-serif;
    font-size: 14px;
}

body.login-page {
    display: grid;
    grid-template-columns: 1fr;
    place-items: center;
    padding: 24px;
    background: #eef3f8;
}

button,
input,
select,
textarea {
    font: inherit;
}

button {
    border: 0;
    cursor: pointer;
}

.admin-sidebar {
    min-height: 100vh;
    padding: 18px 14px;
    background: #1b2638;
    color: #fff;
}

.brand {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 8px 8px 22px;
}

.brand-logo,
.brand-mark {
    width: 38px;
    height: 38px;
}

.brand-logo {
    object-fit: contain;
}

.brand-mark {
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: #29a37a;
    font-weight: 700;
}

.brand small,
.session small {
    display: block;
    color: var(--muted);
    margin-top: 3px;
}

.brand small {
    color: #b8c2d1;
}

.login-shell {
    width: min(100%, 420px);
}

.login-panel {
    display: grid;
    gap: 16px;
    padding: 24px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: 0 18px 45px rgba(23, 32, 51, .12);
}

.login-brand {
    padding: 0 0 6px;
    color: var(--ink);
}

.login-brand small {
    color: var(--muted);
}

.login-panel p,
.login-version {
    color: var(--muted);
}

.login-panel form {
    display: grid;
    gap: 14px;
}

.login-panel button {
    min-height: 40px;
    border-radius: 6px;
    background: var(--primary);
    color: #fff;
}

.login-panel button:hover {
    background: var(--primary-dark);
}

.login-panel button:disabled {
    cursor: wait;
    opacity: .72;
}

#loginMessage {
    min-height: 18px;
    color: var(--danger);
    font-weight: 700;
}

.admin-sidebar nav {
    display: grid;
    gap: 6px;
}

.logout-button,
.nav-item {
    width: 100%;
    min-height: 40px;
    padding: 0 12px;
    border-radius: 6px;
    background: transparent;
    color: #dce6f4;
    text-align: left;
}

.logout-button {
    margin-top: 18px;
    border-top: 1px solid rgba(255, 255, 255, .12);
    background: transparent;
    color: #b8c2d1;
}

.logout-button:hover,
.nav-item:hover,
.nav-item.is-active {
    background: #2e3d54;
    color: #fff;
}

.admin-main {
    min-width: 0;
    padding: 24px;
}

.admin-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}

h1,
h2,
p {
    margin: 0;
}

h1 {
    font-size: 26px;
}

h2 {
    font-size: 18px;
}

.admin-header p {
    color: var(--muted);
    margin-top: 5px;
}

.session {
    text-align: right;
}

.metrics {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    padding: 16px;
}

.metrics article,
.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.metrics article {
    padding: 16px;
}

.metrics span {
    display: block;
    color: var(--muted);
    margin-bottom: 6px;
}

.metrics strong {
    font-size: 26px;
    line-height: 1.1;
}

.toolbar,
.panel-search {
    display: grid;
    grid-template-columns: auto minmax(220px, 360px) auto 1fr;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
}

.panel-search {
    grid-template-columns: auto minmax(220px, 360px) auto auto auto 1fr;
    margin: 0;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
}

.is-hidden {
    display: none !important;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--ink);
}

input,
select {
    min-height: 38px;
    padding: 0 10px;
}

select[multiple] {
    min-height: 150px;
    padding: 8px 10px;
}

.form-help {
    display: block;
    margin-top: 6px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.4;
}

textarea {
    min-height: 76px;
    padding: 10px;
    resize: vertical;
}

.toolbar button,
.panel-head button,
dialog footer button[type="submit"] {
    min-height: 38px;
    padding: 0 14px;
    border-radius: 6px;
    background: var(--primary);
    color: #fff;
}

.toolbar button:hover,
.panel-head button:hover,
dialog footer button[type="submit"]:hover {
    background: var(--primary-dark);
}

.panel {
    overflow: hidden;
}

.panel.is-hidden {
    display: none;
}

.panel-head {
    min-height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0 16px;
    border-bottom: 1px solid var(--line);
}

.panel-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.dashboard-grid,
.dashboard-wide {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    padding: 16px;
}

.dashboard-grid {
    padding-top: 0;
}

.dashboard-wide {
    grid-template-columns: 1fr;
    padding-top: 0;
}

.dashboard-grid article,
.dashboard-wide article {
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcfe;
    padding: 14px;
}

.dashboard-grid h3,
.dashboard-wide h3 {
    margin: 0 0 12px;
    font-size: 15px;
}

.dashboard-grid dl {
    display: grid;
    gap: 8px;
    margin: 0;
}

.dashboard-grid dl div {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid #edf1f6;
    padding-bottom: 8px;
}

.dashboard-grid dl div:last-child {
    border-bottom: 0;
    padding-bottom: 0;
}

.dashboard-grid dt,
.dashboard-grid dd {
    margin: 0;
}

.dashboard-grid dt {
    color: var(--muted);
}

.dashboard-grid dd {
    font-weight: 700;
    text-align: right;
}

.dashboard-wide .table-wrap {
    border: 1px solid var(--line);
    border-radius: 6px;
}

.table-wrap {
    overflow: auto;
}

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

th,
td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    white-space: nowrap;
}

th {
    background: #f8fafc;
    color: #3f4b5f;
    font-weight: 700;
}

th button {
    padding: 0;
    background: transparent;
    color: inherit;
    font-weight: inherit;
    text-align: left;
}

.wide-text {
    min-width: 260px;
}

.truncate-cell {
    max-width: 360px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.color-chip {
    width: 24px;
    height: 24px;
    display: inline-block;
    border: 1px solid var(--line);
    border-radius: 4px;
    vertical-align: middle;
}

.link-action {
    min-height: 30px;
    padding: 0 10px;
    border-radius: 6px;
    background: #e9eef5;
    color: var(--primary-dark);
    font-weight: 700;
}

.link-action:hover {
    background: #dce6f4;
}

.asset-badge {
    display: inline-block;
    margin-left: 6px;
    padding: 2px 6px;
    border-radius: 4px;
    background: #edf7f2;
    color: var(--accent);
    font-size: 11px;
    font-weight: 700;
    vertical-align: middle;
}

td.empty {
    color: var(--muted);
    text-align: center;
}

.status-expired {
    color: var(--danger);
    font-weight: 700;
}

.status-ok {
    color: var(--accent);
    font-weight: 700;
}

dialog {
    width: min(620px, calc(100vw - 28px));
    border: 0;
    border-radius: 8px;
    padding: 0;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .24);
}

dialog.wide-dialog {
    width: min(980px, calc(100vw - 28px));
}

dialog::backdrop {
    background: rgba(15, 23, 42, .45);
}

dialog form {
    display: grid;
    gap: 14px;
    padding: 18px;
}

.panel-form {
    display: grid;
    gap: 14px;
    padding: 18px 28px;
    max-width: 860px;
}

.panel-form h3 {
    margin: 8px 0 0;
    font-size: 15px;
}

.panel-form footer {
    display: flex;
    justify-content: flex-start;
}

.form-separator {
    width: 100%;
    border: 0;
    border-top: 1px solid var(--line);
    margin: 8px 0 2px;
}

.primary-action {
    min-height: 40px;
    padding: 0 18px;
    border-radius: 6px;
    background: var(--primary);
    color: #fff;
    font-weight: 700;
}

.primary-action:hover {
    background: var(--primary-dark);
}

.detail-dialog {
    display: grid;
    gap: 14px;
    padding: 18px;
}

.detail-dialog header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.detail-dialog header button {
    min-height: 36px;
    padding: 0 12px;
    border-radius: 6px;
    background: #e9eef5;
    color: var(--ink);
}

.detail-dialog h3 {
    margin: 4px 0 0;
    font-size: 15px;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.detail-grid article {
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 10px;
    background: #fbfcfe;
}

.detail-grid span {
    display: block;
    color: var(--muted);
    margin-bottom: 4px;
}

.detail-grid strong {
    display: block;
}

.activity-toolbar {
    display: grid;
    grid-template-columns: auto minmax(190px, 260px) auto auto 1fr;
    align-items: center;
    gap: 10px;
}

.activity-summary {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.activity-section {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcfe;
    padding: 12px;
}

.activity-section h3 {
    margin: 0 0 10px;
    font-size: 15px;
}

.activity-section dl {
    display: grid;
    gap: 8px;
    margin: 0;
}

.activity-section dl div {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid #edf1f6;
    padding-bottom: 8px;
}

.activity-section dl div:last-child {
    border-bottom: 0;
    padding-bottom: 0;
}

.activity-section dt,
.activity-section dd {
    margin: 0;
}

.activity-section dt {
    color: var(--muted);
}

.activity-section dd {
    font-weight: 700;
    text-align: right;
}

.table-wrap.compact th,
.table-wrap.compact td {
    padding: 9px 10px;
}

dialog header,
dialog footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

dialog header button,
dialog footer button {
    min-height: 36px;
    padding: 0 12px;
    border-radius: 6px;
    background: #e9eef5;
    color: var(--ink);
}

label {
    display: grid;
    gap: 6px;
    color: #39465a;
    font-weight: 700;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.sale-picker {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
    gap: 10px;
}

.sale-picker button {
    min-height: 38px;
    padding: 0 14px;
    border-radius: 6px;
    background: var(--primary);
    color: #fff;
    font-weight: 700;
}

.sale-cart-wrap {
    border: 1px solid var(--line);
    border-radius: 8px;
}

.sale-quantity {
    width: 82px;
}

.sale-remove {
    min-height: 30px;
    padding: 0 10px;
    border-radius: 6px;
    background: #eef2f7;
    color: var(--ink);
}

.inline-check {
    display: flex;
    align-items: center;
    gap: 8px;
}

.inline-check input {
    width: 16px;
    min-height: 16px;
}

.form-notice {
    padding: 10px 12px;
    border: 1px solid #f3d38b;
    border-radius: 6px;
    background: #fff8e6;
    color: #6f4b00;
    font-weight: 700;
}

.form-notice.is-hidden {
    display: none;
}

.result-box {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcfe;
    padding: 14px;
    line-height: 1.7;
}

.photo-preview {
    width: 150px;
    height: 150px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fafc;
}

.logo-preview {
    width: 180px;
    min-height: 110px;
    display: grid;
    place-items: center;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fafc;
}

.logo-preview img {
    max-width: 100%;
    max-height: 150px;
    display: block;
    object-fit: contain;
}

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

#toast {
    position: fixed;
    right: 18px;
    bottom: 18px;
    max-width: 360px;
    padding: 12px 14px;
    border-radius: 8px;
    background: #172033;
    color: #fff;
    opacity: 0;
    transform: translateY(12px);
    transition: opacity .18s ease, transform .18s ease;
    pointer-events: none;
}

#toast.is-visible {
    opacity: 1;
    transform: translateY(0);
}

@media (max-width: 920px) {
    body {
        grid-template-columns: 1fr;
    }

    .admin-sidebar {
        min-height: auto;
    }

    .metrics {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .dashboard-grid,
    .dashboard-wide {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    .admin-main {
        padding: 16px;
    }

    .admin-header,
    .panel-head,
    .panel-actions,
    dialog header,
    dialog footer {
        align-items: stretch;
        flex-direction: column;
    }

    .session {
        text-align: left;
    }

    .metrics,
    .toolbar,
    .panel-search,
    .detail-grid,
    .activity-toolbar,
    .activity-summary,
    .form-grid {
        grid-template-columns: 1fr;
    }
}
