:root {
    --bg: #ffffff;
    --surface: #ffffff;
    --line: #dfe3e6;
    --line-strong: #c5cbd0;
    --text: #202428;
    --muted: #6b737b;
    --green: #16834a;
    --green-dark: #116a3b;
    --blue: #1769aa;
    --red: #c63434;
    --sidebar-width: 238px;
    --radius: 6px;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; font-family: Arial, "Noto Sans", sans-serif; color: var(--text); background: var(--bg); font-size: 14px; }
a { color: var(--blue); text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { touch-action: manipulation; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.hidden { display: none !important; }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #fff; }
.login-card { width: min(100%, 390px); border: 1px solid var(--line); border-radius: 8px; padding: 32px; background: #fff; box-shadow: 0 8px 28px rgba(0,0,0,.05); }
.login-card h1 { margin: 0 0 6px; font-size: 26px; }
.login-card .muted { margin: 0 0 24px; }

.app-shell { min-height: 100vh; }
.sidebar { position: fixed; inset: 0 auto 0 0; z-index: 80; width: var(--sidebar-width); background: #fff; border-right: 1px solid var(--line); display: flex; flex-direction: column; overflow-y: auto; }
.sidebar-brand { padding: 22px 20px 18px; font-size: 20px; font-weight: 700; border-bottom: 1px solid var(--line); }
.sidebar-nav { padding: 10px 10px 20px; flex: 1; }
.nav-group-label { padding: 16px 12px 6px; color: var(--muted); font-size: 12px; letter-spacing: .04em; }
.sidebar .nav-link { display: block; padding: 10px 12px; border-radius: 5px; color: #30363b; margin: 1px 0; }
.sidebar .nav-link:hover { background: #f2f4f5; }
.sidebar .nav-link.active { color: #0f6638; background: #edf8f2; font-weight: 700; }
.sidebar-version { border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; padding: 14px 20px; }
.app-main { min-height: 100vh; margin-left: var(--sidebar-width); display: flex; flex-direction: column; }
.topbar { height: 62px; background: #fff; border-bottom: 1px solid var(--line); display: flex; align-items: center; padding: 0 24px; position: sticky; top: 0; z-index: 50; }
.topbar-title { font-size: 18px; font-weight: 700; }
.topbar-user { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.topbar-user form { margin: 0; }
.menu-toggle { display: none; border: 0; background: transparent; font-size: 25px; width: 44px; height: 44px; margin-right: 8px; border-radius: 5px; }
.content { width: min(100%, 1500px); margin: 0 auto; padding: 24px; flex: 1; }
.app-footer { text-align: center; color: var(--muted); font-size: 12px; padding: 12px 24px 22px; }
.sidebar-backdrop { display: none; }

.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.page-head h1 { font-size: 22px; margin: 0; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: none; }
.card + .card { margin-top: 18px; }
.card-header { padding: 14px 18px; border-bottom: 1px solid var(--line); font-weight: 700; background: #fff; }
.card-body { padding: 18px; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.cols-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.span-full { grid-column: 1 / -1; }
.stat-grid { display: grid; grid-template-columns: repeat(6, minmax(130px,1fr)); gap: 12px; margin-bottom: 18px; }
.stat-card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.stat-card .label { color: var(--muted); font-size: 13px; }
.stat-card .value { font-size: 24px; font-weight: 700; margin-top: 8px; }
.stat-card .value.multi-money { display: grid; gap: 2px; font-size: 17px; }

.field-label { display: block; margin: 0 0 6px; font-weight: 600; }
.form-control, .form-select { display: block; width: 100%; min-height: 42px; padding: 9px 11px; border: 1px solid var(--line-strong); border-radius: 5px; color: var(--text); background: #fff; }
textarea.form-control { min-height: 86px; resize: vertical; }
.form-control:focus, .form-select:focus { border-color: #7fa9c8; outline: 3px solid rgba(23,105,170,.1); box-shadow: none; }
.form-help { color: var(--muted); font-size: 12px; margin-top: 5px; }
.check-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 18px; }
.check-label { display: inline-flex; gap: 7px; align-items: center; min-height: 36px; }
.password-wrap { position: relative; margin-bottom: 18px; }
.password-wrap .form-control { padding-right: 50px; }
.password-toggle { position: absolute; inset: 0 0 0 auto; width: 46px; border: 0; background: transparent; cursor: pointer; }
.login-card .field-label { margin-top: 16px; }

.btn { min-height: 38px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid transparent; border-radius: 5px; padding: 8px 14px; cursor: pointer; white-space: nowrap; font-weight: 600; line-height: 1.2; }
.btn.primary { color: #fff; background: var(--green); border-color: var(--green); }
.btn.primary:hover { background: var(--green-dark); }
.btn.blue { color: #fff; background: var(--blue); border-color: var(--blue); }
.btn.danger { color: #fff; background: var(--red); border-color: var(--red); }
.btn.secondary { color: #30363b; background: #f2f4f5; border-color: var(--line-strong); }
.btn.outline { color: #30363b; background: #fff; border-color: var(--line-strong); }
.btn.small { min-height: 32px; padding: 6px 10px; font-size: 12px; }
.btn.full { width: 100%; margin-top: 6px; }
.btn.link-btn { color: var(--blue); background: transparent; border: 0; padding: 4px; min-height: 32px; }
.button-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.alert { border: 1px solid; border-radius: 5px; padding: 11px 14px; margin: 0 0 16px; }
.alert.success { background: #effaf4; border-color: #9bd0b3; color: #145f38; }
.alert.danger { background: #fff2f2; border-color: #e3abab; color: #8d2525; }
.alert.warning { background: #fff9e9; border-color: #e6cf8c; color: #745713; }
.alert.info { background: #eef7fd; border-color: #a8cadf; color: #245b7c; }

.table-wrap { width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: 5px; background: #fff; }
.data-table { width: 100%; border-collapse: collapse; min-width: 760px; }
.data-table th, .data-table td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.data-table th { background: #fafafa; font-size: 12px; color: #4d555c; white-space: nowrap; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table .actions-cell { display: flex; gap: 6px; flex-wrap: wrap; min-width: 190px; }
.status { display: inline-flex; padding: 3px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.status.draft { background: #f0f1f2; color: #535a60; }
.status.issued, .status.active { background: #e8f7ef; color: #156b3d; }
.status.void, .status.inactive { background: #fdecec; color: #9a2b2b; }
.filter-bar { display: grid; grid-template-columns: 2fr repeat(4,minmax(130px,1fr)) auto; gap: 10px; align-items: end; }

.modal-layer { position: fixed; inset: 0; z-index: 200; display: none; place-items: center; padding: 20px; background: rgba(20,25,28,.38); }
.modal-layer.open { display: grid; }
.modal-box { width: min(100%, 760px); max-height: calc(100vh - 40px); overflow: auto; background: #fff; border-radius: 7px; border: 1px solid var(--line); }
.modal-head { display: flex; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-close { margin-left: auto; border: 0; background: transparent; font-size: 23px; width: 38px; height: 38px; }
.modal-body { padding: 18px; }

.document-items .item-row { min-width: 1018px; }
.item-row { display: grid; grid-template-columns: 70px 170px 125px minmax(280px,1fr) 110px 135px 135px 44px; gap: 8px; align-items: start; margin-bottom: 8px; }
.item-header { color: var(--muted); font-size: 12px; font-weight: 700; }
.item-amount { min-height: 42px; display: flex; align-items: center; justify-content: flex-end; padding: 9px 10px; background: #f6f7f8; border: 1px solid var(--line); border-radius: 5px; }
.totals-panel { display: flex; justify-content: flex-end; margin-top: 14px; }
.totals-box { width: min(100%, 340px); border-top: 2px solid #222; padding-top: 10px; }
.totals-line { display: flex; justify-content: space-between; font-size: 17px; font-weight: 700; }
.totals-line.subtotal-line { margin-bottom: 7px; color: var(--muted); font-size: 14px; font-weight: 600; }
.customer-preview { min-height: 70px; padding: 11px; background: #fafafa; border: 1px solid var(--line); border-radius: 5px; white-space: pre-line; }

.template-layout { display: grid; grid-template-columns: minmax(330px, 430px) minmax(640px, 1fr); gap: 18px; align-items: start; }
.template-controls { position: sticky; top: 80px; max-height: calc(100vh - 100px); overflow: auto; }
.settings-section { padding: 16px 0; border-bottom: 1px solid var(--line); }
.settings-section:first-child { padding-top: 0; }
.settings-section:last-child { border-bottom: 0; }
.settings-section h3 { margin: 0 0 12px; font-size: 15px; }
.preview-panel { overflow: auto; padding: 14px; background: #e9ebed; border: 1px solid var(--line); border-radius: 5px; }
.preview-scale { transform-origin: top left; }
.column-setting-row { display: grid; grid-template-columns: 1fr 86px 100px; gap: 7px; margin-bottom: 7px; }
.image-thumb { max-width: 220px; max-height: 100px; object-fit: contain; border: 1px solid var(--line); background: #fff; margin: 8px 0; }

.update-card { max-width: 760px; }
.progress-track { height: 18px; border-radius: 99px; background: #e6e9eb; overflow: hidden; margin: 14px 0 8px; }
.progress-bar-real { height: 100%; width: 0; background: var(--green); transition: width .25s ease; }
.update-status { min-height: 24px; }
.code-note { font-family: Consolas, monospace; background: #f5f6f7; padding: 2px 5px; border-radius: 3px; }


.field-label-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 24px; }
.field-label-row .field-label { margin-bottom: 0; }
.toggle-control { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); cursor: pointer; user-select: none; white-space: nowrap; }
.toggle-control input[type="checkbox"] { position: absolute; opacity: 0; pointer-events: none; }
.toggle-track { position: relative; width: 36px; height: 20px; border: 1px solid #cbd2d7; border-radius: 999px; background: #e8ecef; transition: background .15s ease,border-color .15s ease; }
.toggle-thumb { position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform .15s ease; }
.toggle-control input[type="checkbox"]:checked + .toggle-track { background: #16835d; border-color: #16835d; }
.toggle-control input[type="checkbox"]:checked + .toggle-track .toggle-thumb { transform: translateX(16px); }
.toggle-control input[type="checkbox"]:focus-visible + .toggle-track { outline: 2px solid #76a9ff; outline-offset: 2px; }

@media (max-width: 1180px) {
    .stat-grid { grid-template-columns: repeat(3, minmax(130px,1fr)); }
    .template-layout { grid-template-columns: 1fr; }
    .template-controls { position: static; max-height: none; }
}

@media (max-width: 900px) {
    body { font-size: 15px; }
    .sidebar { transform: translateX(-102%); transition: transform .18s ease; box-shadow: 5px 0 20px rgba(0,0,0,.12); }
    body.sidebar-open .sidebar { transform: translateX(0); }
    body.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; z-index: 70; background: rgba(0,0,0,.32); }
    .app-main { margin-left: 0; }
    .menu-toggle { display: inline-grid; place-items: center; }
    .topbar { height: 58px; padding: 0 12px; }
    .topbar-title { font-size: 17px; }
    .topbar-user > span { display: none; }
    .content { padding: 16px 12px; }
    .page-head { align-items: flex-start; flex-wrap: wrap; }
    .page-head .actions { width: 100%; margin-left: 0; }
    .grid.cols-2, .grid.cols-3, .grid.cols-4, .grid.cols-6 { grid-template-columns: 1fr; }
    .span-2 { grid-column: auto; }
    .stat-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
    .stat-card { padding: 14px; }
    .stat-card .value { font-size: 21px; }
    .filter-bar { grid-template-columns: 1fr; }
    .card-body { padding: 14px; }
    .login-card { padding: 24px 20px; border: 0; box-shadow: none; }
    .form-control, .form-select, .btn { min-height: 44px; }
    .template-layout { display: block; }
    .preview-panel { margin-top: 16px; padding: 8px; }
}

@media (max-width: 430px) {
    .stat-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
    .stat-card .label { font-size: 12px; }
}
