:root {
    --ink: #151515;
    --muted: #6b6b6b;
    --line: #dedede;
    --paper: #fff;
    --canvas: #f3f3f1;
    --violet: #7137ff;
    --blue: #2447ff;
    --green: #1bd63f;
    --pink: #ff1491;
    --danger: #b42318;
    --radius: 18px;
    --shadow: 0 18px 50px rgba(0, 0, 0, .07);
}

* { box-sizing: border-box; }
html { font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--ink); background: var(--canvas); }
body { margin: 0; min-height: 100vh; }
a { color: inherit; }
button, input, select, textarea { font: inherit; }
button, .button { -webkit-tap-highlight-color: transparent; }

.app-shell { display: grid; grid-template-columns: 248px 1fr; }
.sidebar { min-height: 100vh; position: fixed; inset: 0 auto 0 0; width: 248px; padding: 30px 22px; background: #101010; color: #fff; display: flex; flex-direction: column; z-index: 10; }
.brand-link { text-decoration: none; display: block; margin-bottom: 46px; }
.brand-link img { display: block; width: 155px; filter: brightness(0) invert(1); }
.brand-link span { display: block; margin-top: 6px; color: #aaa; font-size: 12px; letter-spacing: .13em; text-transform: uppercase; }
.sidebar nav { display: grid; gap: 8px; }
.sidebar nav a, .sidebar-logout { text-decoration: none; color: #d1d1d1; padding: 11px 12px; border-radius: 10px; }
.sidebar nav a:hover, .sidebar-logout:hover { background: #222; color: #fff; }
.sidebar-logout-form { margin-top: auto; }
.sidebar-logout { width: 100%; border: 0; background: transparent; text-align: left; cursor: pointer; }
.main { grid-column: 2; width: min(1180px, calc(100vw - 248px)); padding: 52px clamp(28px, 5vw, 76px) 80px; }

.page-header { display: flex; justify-content: space-between; align-items: flex-end; gap: 22px; margin-bottom: 28px; }
.page-header h1 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: clamp(34px, 5vw, 56px); letter-spacing: -.035em; line-height: .98; }
.eyebrow { color: var(--violet); font-size: 12px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; margin: 0 0 10px; }
.header-meta { margin: 10px 0 0; color: var(--muted); }
.header-actions { display: flex; gap: 10px; }

.button { appearance: none; border: 0; border-radius: 999px; padding: 12px 19px; text-decoration: none; font-weight: 750; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; line-height: 1; min-height: 43px; }
.button.primary { background: var(--ink); color: #fff; box-shadow: 3px 3px 0 var(--pink), -2px -2px 0 var(--blue); }
.button.primary:hover { transform: translateY(-1px); box-shadow: 4px 5px 0 var(--pink), -3px -3px 0 var(--blue); }
.button.ghost { background: #fff; border: 1px solid var(--line); }
.button.small { min-height: 36px; padding: 9px 14px; font-size: 13px; }

.panel { background: var(--paper); border: 1px solid rgba(0,0,0,.08); border-radius: var(--radius); box-shadow: var(--shadow); padding: 26px; margin-bottom: 22px; }
.panel-header, .action-heading { display: flex; justify-content: space-between; align-items: center; gap: 18px; margin-bottom: 18px; }
.panel h2, .section-heading h2 { margin: 0; font-size: 19px; }
.panel-header a { color: var(--violet); font-weight: 700; text-decoration: none; }
.section-heading { padding-bottom: 4px; }
.section-heading p { margin: 5px 0 0; color: var(--muted); font-size: 14px; }

.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; margin-bottom: 22px; }
.stat { background: #fff; border-radius: var(--radius); padding: 24px; border: 1px solid rgba(0,0,0,.08); position: relative; overflow: hidden; }
.stat::after { content: ""; position: absolute; width: 52px; height: 5px; right: 20px; top: 22px; background: linear-gradient(90deg, var(--blue), var(--pink), var(--green)); }
.stat span { color: var(--muted); display: block; font-size: 13px; }
.stat strong { display: block; margin-top: 8px; font-family: Georgia, serif; font-size: clamp(27px, 2.25vw, 38px); white-space: nowrap; }

.responsive-table { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { color: var(--muted); text-align: left; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; border-bottom: 1px solid var(--line); padding: 12px 10px; }
td { border-bottom: 1px solid #ededed; padding: 15px 10px; }
tr:last-child td { border-bottom: 0; }
td a { font-weight: 750; text-decoration-color: #bbb; text-underline-offset: 3px; }
.right { text-align: right; }
.status { display: inline-flex; border-radius: 999px; padding: 5px 10px; font-size: 12px; font-weight: 800; }
.status.open { background: #eee; color: #444; }
.status.paid { background: #dff9e3; color: #176c2b; }
.status.overdue { background: #ffe3df; color: #9d291d; }

.customer-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.customer-card { border: 1px solid var(--line); border-radius: 14px; padding: 18px; text-decoration: none; display: grid; gap: 6px; min-height: 120px; background: #fafafa; }
.customer-card:hover { border-color: var(--violet); background: #fff; }
.customer-card strong { font-family: Georgia, serif; font-size: 19px; }
.customer-card span { color: var(--muted); }
.customer-card small { margin-top: auto; color: var(--violet); font-weight: 800; text-transform: uppercase; letter-spacing: .08em; }

.form-grid { display: grid; gap: 18px; }
.two-columns { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.three-columns { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span-two { grid-column: 1 / -1; }
.span-three { grid-column: 1 / -1; }
.narrow-form { max-width: 840px; }
label { display: grid; gap: 7px; font-size: 12px; font-weight: 800; letter-spacing: .035em; }
label small { color: var(--muted); font-weight: 500; letter-spacing: 0; }
input, select, textarea { width: 100%; border: 1px solid #cfcfcf; border-radius: 10px; padding: 11px 12px; background: #fff; color: var(--ink); font-size: 15px; font-weight: 500; letter-spacing: 0; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--violet); box-shadow: 0 0 0 3px rgba(113,55,255,.12); }
textarea { resize: vertical; line-height: 1.45; }
.form-actions { display: flex; justify-content: flex-end; padding-top: 8px; }
.qr-manager { display: grid; grid-template-columns: 1fr 180px; gap: 24px; align-items: center; padding: 20px; border: 1px solid var(--line); border-radius: 14px; background: #fafaf8; }
.qr-manager h3 { margin: 0 0 6px; font-size: 17px; }
.qr-manager p { margin: 0 0 16px; color: var(--muted); font-size: 13px; line-height: 1.45; }
.qr-current { display: grid; justify-items: center; gap: 10px; }
.qr-current img { display: block; width: 126px; height: 126px; object-fit: contain; padding: 7px; background: #fff; border: 1px solid var(--line); border-radius: 10px; }
.qr-empty { padding: 24px 14px; border: 1px dashed #bbb; border-radius: 10px; color: var(--muted); text-align: center; font-size: 12px; }

.item-editor-list { display: grid; gap: 12px; }
.preset-picker { margin: 0 0 18px; padding: 18px; border: 1px solid #ddd; border-radius: 14px; background: #fafaf8; }
.preset-picker-head { display: flex; justify-content: space-between; gap: 18px; align-items: flex-start; margin-bottom: 14px; }
.preset-picker-head div { display: grid; gap: 3px; }
.preset-picker-head span { color: var(--muted); font-size: 13px; }
.preset-picker-head a, .action-heading a { color: var(--violet); font-size: 13px; font-weight: 800; text-decoration: none; }
.preset-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 14px; }
.preset-option { display: flex; grid-template-columns: none; gap: 10px; align-items: flex-start; padding: 11px 12px; background: #fff; border: 1px solid #ddd; border-radius: 11px; cursor: pointer; }
.preset-option:has(input:checked) { border-color: var(--violet); box-shadow: inset 0 0 0 1px var(--violet); background: #f7f3ff; }
.preset-option input, .check-row input { width: 18px; height: 18px; margin: 1px 0 0; accent-color: var(--violet); }
.preset-option span { display: grid; gap: 3px; }
.preset-option small { color: var(--muted); font-weight: 500; letter-spacing: 0; }
.item-editor { display: grid; grid-template-columns: 38px 1fr 34px; gap: 14px; padding: 18px; background: #f7f7f5; border-radius: 14px; border: 1px solid #e2e2df; }
.item-index { width: 32px; height: 32px; display: grid; place-items: center; background: var(--ink); color: #fff; border-radius: 50%; font-weight: 800; }
.item-fields { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.item-fields .wide { grid-column: 1 / -1; }
.icon-button { width: 32px; height: 32px; border: 0; background: transparent; color: #777; cursor: pointer; border-radius: 50%; font-size: 24px; line-height: 1; }
.icon-button:hover { background: #fff; color: var(--danger); }
.sticky-actions { position: sticky; bottom: 18px; background: rgba(17,17,17,.94); color: #fff; backdrop-filter: blur(14px); border-radius: 16px; padding: 14px 16px 14px 20px; display: flex; justify-content: space-between; align-items: center; gap: 18px; box-shadow: 0 18px 50px rgba(0,0,0,.25); z-index: 5; }
.sticky-actions span { color: #c7c7c7; font-size: 13px; }

.document-toolbar { display: flex; align-items: center; gap: 18px; padding: 14px 18px; }
.document-toolbar form { margin: 0; }
.link-button { border: 0; background: transparent; color: var(--violet); padding: 0; cursor: pointer; font-weight: 750; }
.document-frame { background: #d9d9d6; padding: 28px; border-radius: var(--radius); overflow: auto; }
.document-frame iframe { display: block; margin: 0 auto; width: 794px; max-width: 100%; height: 1123px; border: 0; background: white; box-shadow: 0 15px 50px rgba(0,0,0,.16); }
.document-frame.pdf-frame { padding: 18px; }
.document-frame.pdf-frame iframe { width: 100%; max-width: none; height: max(1123px, calc(100vh - 250px)); }

.template-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.template-card { display: flex; flex-direction: column; min-height: 260px; padding: 22px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; color: inherit; text-decoration: none; box-shadow: var(--shadow); }
.template-card:hover { border-color: var(--violet); transform: translateY(-1px); }
.template-card.is-inactive { opacity: .62; }
.template-card-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.language-badge { display: inline-grid; place-items: center; width: 34px; height: 25px; border-radius: 7px; background: #181818; color: #fff; font-size: 11px; font-weight: 900; letter-spacing: .08em; }
.template-card h2 { margin: 0 0 10px; font-family: Georgia, serif; font-size: 24px; }
.template-card > strong { font-size: 13px; }
.template-card p { color: var(--muted); line-height: 1.5; font-size: 14px; }
.template-edit { margin-top: auto; color: var(--violet); font-weight: 800; font-size: 13px; }
.check-row { display: flex; grid-template-columns: none; flex-direction: row; gap: 10px; align-items: center; padding: 13px; background: #f5f5f3; border-radius: 10px; }

.empty { text-align: center; padding: 54px 24px; }
.empty h3, .empty h1 { margin: 0 0 8px; font-family: Georgia, serif; font-size: 28px; }
.empty p { color: var(--muted); margin: 0 0 20px; }

.import-upload .section-heading { margin-bottom: 18px; }
.import-dropzone { padding: 22px; border: 1px dashed #aaa; border-radius: 14px; background: #fafaf8; }
.import-dropzone input { padding: 14px; border-style: dashed; }
.import-table td { vertical-align: top; }
.import-table td small { display: block; margin-top: 5px; color: var(--muted); font-size: 11px; line-height: 1.35; font-weight: 500; }
.import-table .import-warning { color: #9d5b00; }
.import-check { width: 38px; text-align: center; }
.import-check input { width: 18px; height: 18px; margin: 0; accent-color: var(--violet); }
.file-badge { display: inline-flex; padding: 4px 7px; border-radius: 6px; background: #eee; font-size: 10px; font-weight: 900; letter-spacing: .08em; }
.import-options { margin-top: 20px; padding-top: 20px; border-top: 1px solid var(--line); display: grid; grid-template-columns: minmax(220px, 320px) 1fr; align-items: end; gap: 24px; }
.import-options p { margin: 0 0 11px; color: var(--muted); font-size: 13px; line-height: 1.45; }
.import-skipped { border-color: #ead9bd; }

.flash { position: fixed; z-index: 50; top: 20px; right: 22px; max-width: 440px; padding: 13px 17px; border-radius: 12px; box-shadow: var(--shadow); font-weight: 700; }
.flash-success { background: #dcf9e1; color: #145d25; }
.flash-error { background: #ffe1dd; color: #8d2217; }

.auth-shell { min-height: 100vh; background: #101010; display: grid; place-items: center; padding: 28px; position: relative; overflow-x: hidden; }
.auth-shell::before, .auth-shell::after { content: ""; position: fixed; width: 420px; height: 13px; filter: blur(2px); opacity: .9; transform: rotate(-18deg); }
.auth-shell::before { background: var(--pink); left: -100px; top: 18%; box-shadow: 0 18px 0 var(--blue), 0 -16px 0 var(--green); }
.auth-shell::after { background: var(--blue); right: -100px; bottom: 18%; box-shadow: 0 18px 0 var(--green), 0 -16px 0 var(--pink); }
.auth-main { width: min(900px, 100%); position: relative; z-index: 1; }
.auth-card { width: min(460px, 100%); margin: 0 auto; background: #fff; border-radius: 24px; padding: 34px; box-shadow: 0 30px 100px rgba(0,0,0,.4); }
.setup-card { width: min(900px, 100%); }
.auth-logo { width: 190px; display: block; margin-bottom: 28px; }
.auth-card h1 { font-family: Georgia, serif; font-size: 38px; margin: 0 0 10px; }
.auth-card h2 { font-size: 17px; margin: 14px 0 0; padding-top: 18px; border-top: 1px solid var(--line); }
.lead { color: var(--muted); line-height: 1.55; margin-bottom: 28px; }

@media (max-width: 900px) {
    .app-shell { display: block; }
    .sidebar { position: static; min-height: auto; width: auto; padding: 16px; flex-direction: row; align-items: center; gap: 14px; overflow-x: auto; }
    .brand-link { margin: 0 18px 0 0; min-width: 105px; }
    .brand-link img { width: 105px; }
    .brand-link span, .sidebar-logout-form { display: none; }
    .sidebar nav { display: flex; }
    .sidebar nav a { white-space: nowrap; }
    .main { width: 100%; padding: 34px 20px 70px; }
    .stat-grid, .customer-grid { grid-template-columns: 1fr; }
    .three-columns { grid-template-columns: 1fr 1fr; }
    .span-three { grid-column: 1 / -1; }
}

@media (max-width: 620px) {
    .page-header { align-items: flex-start; flex-direction: column; }
    .page-header h1 { font-size: 40px; }
    .header-actions { width: 100%; }
    .header-actions .button { flex: 1; }
    .two-columns, .three-columns, .item-fields, .template-grid, .preset-options, .qr-manager { grid-template-columns: 1fr; }
    .span-two, .span-three, .item-fields .wide { grid-column: auto; }
    .panel { padding: 18px; border-radius: 14px; }
    .item-editor { grid-template-columns: 32px 1fr; }
    .item-editor .icon-button { grid-column: 2; justify-self: end; }
    .sticky-actions { align-items: stretch; flex-direction: column; }
    .document-frame { padding: 8px; }
    .document-frame iframe { height: 780px; }
    .auth-card { padding: 24px; }
}
