:root {
    --yellow: #FFF700;
    --yellow-deep: #F3C914;
    --black: #000000;
    --bg-app: #0f172a;
    --bg-app-2: #111827;
    --surface: #1e293b;
    --surface-soft: #243449;
    --input: #020617;
    --ink: #f8fafc;
    --muted: #94a3b8;
    --line: #334155;
    --paper: #ffffff;
    --paper-soft: #f5f5f5;
    --danger: #ef4444;
    --warn: #f59e0b;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,.25);
    --shadow-md: 0 12px 30px rgba(0,0,0,.28);
    --glow: 0 0 24px rgba(255,247,0,.16);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    font-family: "Segoe UI", Inter, system-ui, -apple-system, sans-serif;
    background:
        radial-gradient(circle at 18% -8%, rgba(255,247,0,.12), transparent 34%),
        linear-gradient(180deg, var(--bg-app) 0%, #0b1120 100%);
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 20;
    height: 66px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 0 22px;
    background: linear-gradient(135deg, #050505 0%, #151515 58%, #222000 100%);
    color: white;
    border-bottom: 3px solid var(--yellow);
    box-shadow: var(--shadow-md);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand img {
    width: 54px;
    height: 54px;
    object-fit: contain;
    border-radius: 10px;
    box-shadow: 0 0 0 1px rgba(255,247,0,.28), var(--glow);
}
.brand strong { display: block; color: var(--yellow); font-size: 15px; letter-spacing: .2px; }
.brand span {
    display: inline-flex;
    margin-top: 4px;
    color: #d1d5db;
    font-size: 12px;
    border: 1px solid rgba(255,247,0,.26);
    border-radius: 6px;
    padding: 3px 8px;
    background: rgba(255,247,0,.08);
}

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.icon-btn, button, .button-link {
    min-height: 38px;
    border: 1px solid rgba(255,255,255,.12);
    background: rgba(255,255,255,.06);
    color: rgba(255,255,255,.88);
    padding: 0 13px;
    border-radius: var(--radius-sm);
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    transition: transform .16s ease, border-color .16s ease, background .16s ease, color .16s ease;
}
.icon-btn:hover, button:hover, .button-link:hover {
    transform: translateY(-1px);
    border-color: rgba(255,247,0,.45);
    color: white;
    background: rgba(255,255,255,.12);
}
.icon-btn.primary, button.primary {
    background: var(--yellow);
    color: var(--black);
    border-color: var(--yellow);
    box-shadow: 0 8px 20px rgba(255,247,0,.16);
}

.main-shell {
    display: grid;
    grid-template-columns: minmax(0, 1.28fr) minmax(420px, 520px);
    gap: 18px;
    padding: 20px;
    max-width: 1500px;
    margin: 0 auto;
    align-items: start;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 20px 22px;
    box-shadow: var(--shadow-sm);
}
.summary-panel {
    position: sticky;
    top: 84px;
    max-height: calc(100vh - 104px);
    overflow: auto;
}

h1, h2 { color: var(--ink); margin-top: 0; }
h1 {
    margin-bottom: 18px;
    font-size: 22px;
    line-height: 1.1;
    display: flex;
    align-items: center;
    gap: 10px;
}
h1::before, h2::before {
    content: "";
    width: 9px;
    height: 22px;
    border-radius: 999px;
    background: var(--yellow);
    box-shadow: var(--glow);
    flex: 0 0 auto;
}
h2 {
    margin: 20px 0 12px;
    font-size: 15px;
    display: flex;
    align-items: center;
    gap: 9px;
}

label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .05em;
}
input, select, textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    color: var(--ink);
    background: var(--input);
    font: inherit;
    font-size: 13px;
    transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}
textarea { resize: vertical; min-height: 42px; }
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--yellow);
    box-shadow: 0 0 0 3px rgba(255,247,0,.14);
    background: #030712;
}
input::placeholder, textarea::placeholder { color: #64748b; }

.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.compact input, .compact select { min-height: 38px; }

.ai-box {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    align-items: end;
    margin: 16px 0;
    padding: 14px;
    background: linear-gradient(135deg, rgba(255,247,0,.12), rgba(255,247,0,.04));
    border: 1px solid rgba(255,247,0,.34);
    border-radius: var(--radius);
}
.ai-editor { display: grid; gap: 12px; min-width: 0; }
.ai-box button {
    background: var(--yellow);
    color: var(--black);
    border-color: var(--yellow);
}

.concept-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 11px; }
.type-selector, .size-selector, .extras { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }

.choice {
    min-width: 104px;
    border: 2px solid var(--line);
    background: var(--input);
    color: var(--muted);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    cursor: pointer;
    text-align: left;
    transition: transform .16s ease, border-color .16s ease, background .16s ease, color .16s ease;
}
.choice:hover {
    transform: translateY(-1px);
    color: var(--ink);
    border-color: rgba(255,247,0,.55);
    background: var(--surface-soft);
}
.choice.active {
    color: var(--black);
    background: var(--yellow);
    border-color: var(--yellow);
    box-shadow: var(--glow);
}
.choice small { display: block; color: inherit; opacity: .76; margin-top: 3px; font-size: 11px; }
.type-choice {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    min-width: 155px;
}
.type-icon {
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    display: inline-grid;
    place-items: center;
    border-radius: 8px;
    border: 1px solid currentColor;
    background: rgba(255,255,255,.04);
}
.type-icon svg {
    width: 29px;
    height: 29px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.choice.active .type-icon {
    background: rgba(0,0,0,.08);
}

.items-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    overflow: hidden;
    border-radius: var(--radius-sm);
}
.items-table th, .items-table td {
    border-bottom: 1px solid var(--line);
    padding: 8px;
    text-align: left;
    vertical-align: top;
}
.items-table th {
    background: #050505;
    color: var(--yellow);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.items-table tr:hover td { background: rgba(255,255,255,.03); }
.items-table input { padding: 7px; }
.items-table .num { text-align: right; }
.row-actions { display: inline-flex; gap: 6px; align-items: center; }
.row-actions form { margin: 0; }
.row-actions button, .row-actions .button-link { min-height: 28px; padding: 0 9px; }

.discount-row { display: grid; grid-template-columns: 1fr 80px; gap: 8px; margin-top: 14px; }
.totals {
    margin-top: 14px;
    border-top: 2px solid var(--yellow);
    padding-top: 8px;
}
.totals div {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255,255,255,.08);
    color: var(--muted);
}
.totals strong { color: var(--ink); }
.totals .grand {
    margin: 8px -8px 0;
    padding: 12px 8px;
    color: var(--black);
    background: var(--yellow);
    border-radius: var(--radius-sm);
    border-bottom: 0;
    font-size: 20px;
    font-weight: 900;
}
.totals .grand strong { color: var(--black); }

.toast {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 80;
    background: #050505;
    color: white;
    border: 1px solid rgba(255,247,0,.32);
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s;
    max-width: 360px;
    box-shadow: var(--shadow-md);
}
.toast.show { opacity: 1; }

.login-shell {
    min-height: 100vh;
    width: min(100%, 560px);
    margin: 0 auto;
    padding: 24px;
    display: grid;
    place-items: center;
}
.login-shell .panel {
    width: 100%;
    background: linear-gradient(180deg, #1e293b, #151f2e);
    padding: 34px 38px;
}
.login-logo {
    display: block;
    width: 210px;
    max-width: 72%;
    height: auto;
    margin: 0 0 28px;
}
.login-shell h1 {
    margin-bottom: 28px;
    font-size: 28px;
    line-height: 1.12;
}
.login-form {
    display: grid;
    gap: 22px;
}
.login-form input {
    min-height: 58px;
    font-size: 18px;
    font-weight: 700;
}
.login-form button {
    width: fit-content;
    min-width: 114px;
    min-height: 56px;
    padding: 0 24px;
    font-size: 18px;
}

.templates-shell {
    grid-template-columns: minmax(340px, 420px) minmax(0, 1fr);
    max-width: 1600px;
}
.template-form-panel { position: sticky; top: 84px; }
.template-toolbar {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    margin-bottom: 18px;
}
.template-filters {
    flex: 1;
    display: grid;
    grid-template-columns: minmax(180px, 1fr) 180px 150px auto;
    gap: 10px;
}
.prompt-table th:nth-child(4), .prompt-table td:nth-child(4) { width: 42%; }
.prompt-cell {
    color: #dbeafe;
    line-height: 1.45;
    font-size: 12px;
}
.pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    padding: 4px 9px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 800;
    white-space: nowrap;
}
.pill.blue { color: #bfdbfe; background: #1d4ed8; }
.pill.green { color: #d1fae5; background: #047857; }
.pill.muted { color: #d1d5db; background: rgba(255,255,255,.08); }
.notice { font-weight: 800; }
.notice.ok { color: #4ade80; }
.notice.error { color: #f87171; }
.hint {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.45;
}
.check-row {
    display: inline-flex;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: 8px;
}
.check-row input { width: auto; }
.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 12px;
}
.section-head h1,
.section-head h2 { margin: 0; }
.eyebrow {
    margin: 0 0 8px;
    color: var(--yellow);
    font-size: 12px;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: .05em;
}
.password-field {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
}
.password-field input { min-width: 0; }
.icon-eye {
    min-width: 58px;
    padding: 0 10px;
}

.preview-drawer {
    position: fixed;
    inset: 0 0 0 auto;
    z-index: 70;
    width: min(920px, 100vw);
    background: #ffffff;
    color: #111111;
    border-left: 3px solid var(--yellow);
    box-shadow: -24px 0 60px rgba(0,0,0,.28);
    transform: translateX(104%);
    transition: transform .22s ease;
    display: grid;
    grid-template-rows: auto 1fr;
}
.preview-drawer.open { transform: translateX(0); }
.preview-head {
    min-height: 58px;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid #e5e7eb;
    background: #ffffff;
    color: #111111;
}
.preview-head strong {
    color: #111111;
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.preview-head button {
    background: #111111;
    color: #ffffff;
    border-color: #111111;
}
.preview-head button:first-child {
    background: var(--yellow);
    color: #000000;
    border-color: #000000;
}
.preview-body {
    overflow: auto;
    padding: 22px;
    background: #f8fafc;
}
#quotation-sheet-preview {
    width: 210mm;
    min-height: 270mm;
    margin: 0 auto;
    padding: 16mm;
    background: white;
    color: #111111;
    transform-origin: top center;
    box-shadow: 0 16px 42px rgba(15,23,42,.14);
    border: 1px solid #e5e7eb;
}
#quotation-sheet-preview * {
    color: inherit;
}
#quotation-sheet-preview .q-logo-img {
    display: block;
}
#quotation-sheet-preview .q-meta-title,
#quotation-sheet-preview .q-table th {
    color: #ffffff;
}
#quotation-sheet-preview .q-grand-total,
#quotation-sheet-preview .q-grand-total * {
    color: #000000;
}

.dashboard-shell,
.catalog-shell {
    grid-template-columns: 1fr;
    max-width: 1500px;
}
.dashboard-hero {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 18px;
    padding: 22px;
    background: linear-gradient(135deg, #050505, #1f2937 70%, #2b2a00);
    border: 1px solid rgba(255,247,0,.24);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
}
.dashboard-hero p { margin: 4px 0 0; color: var(--muted); }
.metric-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(150px, 1fr));
    gap: 12px;
}
.metric-card {
    min-height: 110px;
    padding: 16px;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--line);
    display: grid;
    align-content: space-between;
}
.metric-card span {
    color: var(--muted);
    font-size: 11px;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: .05em;
}
.metric-card strong {
    color: var(--yellow);
    font-size: 25px;
    line-height: 1.05;
}
.dashboard-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.55fr) minmax(280px, .8fr);
    gap: 18px;
}
.bar-chart { display: grid; gap: 12px; }
.bar-row {
    display: grid;
    grid-template-columns: 82px 1fr 130px;
    gap: 10px;
    align-items: center;
    color: var(--muted);
    font-size: 12px;
}
.user-bar-row { grid-template-columns: minmax(120px, 220px) 1fr 130px; }
.bar-row div {
    height: 14px;
    overflow: hidden;
    border-radius: 999px;
    background: rgba(255,255,255,.08);
}
.bar-row i {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--yellow);
}
.bar-row strong,
.status-list strong { color: var(--ink); text-align: right; }
.status-list { display: grid; gap: 10px; }
.status-list div {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: rgba(255,255,255,.03);
}

.catalog-type-card,
.catalog-extra-form {
    margin: 0 0 16px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(255,255,255,.025);
}
.price-grid {
    display: grid;
    grid-template-columns: repeat(8, minmax(84px, 1fr));
    gap: 9px;
    margin: 14px 0;
}
.price-grid label { font-size: 10px; }
.price-grid input { padding: 8px; }
.catalog-actions {
    display: flex;
    align-items: end;
    justify-content: flex-end;
    gap: 12px;
    flex-wrap: wrap;
}
.catalog-actions label:not(.check-row) { width: 110px; }

#quotation-sheet {
    display: none;
    width: 210mm;
    min-height: 270mm;
    margin: 20px auto;
    padding: 16mm;
    background: white;
    color: #222;
    font-family: Arial, sans-serif;
}
.q-header-top { display: flex; justify-content: space-between; gap: 24px; align-items: flex-start; }
.q-brand-block { min-width: 0; }
.q-logo-img { width: 74px; max-height: 74px; object-fit: contain; object-position: left center; }
.q-slogan { font-size: 13px; font-weight: bold; margin-top: 8px; color: #111; }
.q-address { font-size: 10px; line-height: 1.35; margin-top: 4px; color: #444; }
.q-meta { text-align: right; font-size: 12px; min-width: 180px; color: #222; }
.q-meta-title {
    display: inline-block;
    background: #111;
    color: #fff;
    padding: 8px 12px;
    font-weight: bold;
    text-transform: uppercase;
    font-size: 14px;
    letter-spacing: .08em;
}
.q-meta-row { margin-top: 5px; }
.q-yellow-bar { height: 8px; background: var(--yellow); border: 1px solid #000; margin: 18px 0 14px; }
.q-client-box { margin-bottom: 14px; background: #f5f5f5; padding: 12px 14px; border-left: 5px solid var(--yellow-deep); }
.q-attn-label { font-size: 10px; color: #000; font-weight: bold; text-transform: uppercase; margin-bottom: 5px; }
.q-attn-label.black { color: #000; }
.q-client-name { font-size: 18px; font-weight: bold; color: #222; margin-bottom: 8px; text-transform: uppercase; }
.q-intro-text { font-size: 12px; color: #333; }
.q-table { width: 100%; border-collapse: collapse; margin-top: 10px; }
.q-table th {
    background-color: #111;
    color: white;
    padding: 12px 15px;
    text-align: left;
    font-size: 11px;
    text-transform: uppercase;
}
.q-table td { border-bottom: 1px solid #ddd; padding: 12px 15px; font-size: 12px; vertical-align: top; color: #222; }
.desc-title { font-weight: bold; text-transform: uppercase; margin-bottom: 4px; }
.desc-detail { font-size: 11px; color: #555; line-height: 1.4; }
.q-footer-layout { display: flex; justify-content: space-between; gap: 25px; margin-top: 22px; align-items: flex-start; }
.q-terms { flex: 1; font-size: 11px; line-height: 1.45; color: #222; }
.q-terms ul { margin: 8px 0 0 18px; padding: 0; }
.q-signature { width: 240px; margin-top: 48px; text-align: center; }
.q-agent-name { border-top: 1px solid #000; padding-top: 8px; font-weight: bold; text-transform: uppercase; }
.q-agent-title { font-size: 10px; color: #555; margin-top: 3px; }
.q-totals { width: 250px; text-align: right; color: #222; }
.q-row-total { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid #eee; font-size: 12px; gap: 12px; }
.q-grand-total { display: flex; justify-content: space-between; padding: 12px; font-size: 16px; font-weight: bold; background: var(--yellow); color: #000; margin-top: 8px; border: 1px solid #000; }
.top-gap { margin-top: 10px; }

@media (max-width: 1100px) {
    .app-header { height: auto; padding: 10px 14px; align-items: flex-start; }
    .main-shell { grid-template-columns: 1fr; padding: 14px; }
    .templates-shell { grid-template-columns: 1fr; }
    .template-form-panel { position: static; }
    .template-toolbar { align-items: stretch; flex-direction: column; }
    .template-filters { grid-template-columns: 1fr; }
    .summary-panel { position: static; max-height: none; }
    .dashboard-grid { grid-template-columns: 1fr; }
    .metric-grid { grid-template-columns: repeat(2, 1fr); }
    .price-grid { grid-template-columns: repeat(4, minmax(76px, 1fr)); }
    .grid-3, .grid-4, .concept-grid { grid-template-columns: 1fr; }
    .ai-box { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
    .app-header { flex-direction: column; }
    .brand img { width: 46px; height: 46px; }
    .toolbar { width: 100%; justify-content: stretch; }
    .toolbar .icon-btn, .toolbar button { flex: 1 1 auto; }
    .panel { padding: 16px; }
    .login-shell {
        width: 100%;
        min-height: 100vh;
        padding: 18px;
        align-items: center;
    }
    .login-shell .panel {
        padding: 24px 20px;
        border-radius: 10px;
    }
    .login-logo {
        width: 150px;
        max-width: 82%;
        margin-bottom: 22px;
    }
    .login-shell h1 {
        font-size: 21px;
        line-height: 1.18;
        margin-bottom: 22px;
    }
    .login-form {
        gap: 18px;
    }
    .login-form input {
        min-height: 48px;
        font-size: 15px;
    }
    .login-form button {
        min-height: 46px;
        min-width: 92px;
        font-size: 14px;
    }
    .metric-grid { grid-template-columns: 1fr; }
    .bar-row { grid-template-columns: 70px 1fr; }
    .bar-row strong { grid-column: 2; text-align: left; }
    .price-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .preview-body { padding: 12px; }
    #quotation-sheet-preview { transform: none; width: 100%; min-height: auto; padding: 18px; margin: 0; }
}

@media print {
    @page { size: letter; margin: 10mm; }
    body { background: white; color: #222; }
    .no-print { display: none !important; }
    #quotation-sheet {
        display: block !important;
        width: auto;
        min-height: auto;
        margin: 0;
        padding: 0;
        box-shadow: none;
    }
}
