:root {
  --app-bg: #eef4f8;
  --brand: #12324a;
  --accent: #00a6a6;
  --accent-hover: #078f92;
  --text: #17212b;
  --muted: #5d6a75;
  --card: #ffffff;
  --grid: #d7e1e8;
  --table: #fbfdff;
  --table-head: #e5edf3;
  --status: #dbeaf2;
  --danger: #a33b3b;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; display: flex; flex-direction: column; color: var(--text); background: var(--app-bg); font: 14px "Segoe UI", Arial, sans-serif; }
button, input, select { font: inherit; }
button { cursor: pointer; }

.app-header { min-height: 78px; padding: 13px 18px; display: flex; align-items: center; justify-content: space-between; gap: 24px; color: white; background: var(--brand); }
.title-block h1 { margin: 0; color: white; font-size: 25px; line-height: 1.15; }
.title-block p { margin: 4px 0 0; color: #c8e9ee; font-size: 13px; font-weight: 700; }
.header-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.connection { min-height: 36px; padding: 0 10px; display: flex; align-items: center; gap: 8px; border: 1px solid rgba(255,255,255,.2); border-radius: 5px; color: #d7e7ee; font-size: 12px; white-space: nowrap; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #f3b64b; }
.connection.ok .status-dot { background: #44d18a; }

.button { min-height: 36px; padding: 7px 13px; border: 1px solid #b8c6cf; border-radius: 4px; color: var(--text); background: #f8fbfd; font-weight: 700; }
.button:hover { background: #eaf2f6; }
.button.primary { color: white; border-color: var(--accent); background: var(--accent); }
.button.primary:hover { background: var(--accent-hover); }
.header-button { color: var(--text); border-color: #d5e0e6; background: #f8fbfd; }
.tall-button { min-height: 48px; padding-inline: 18px; }
.tool-button { min-height: 34px; padding: 6px 11px; font-weight: 500; }
.link-button { padding: 2px 4px; border: 0; color: #087f83; background: transparent; font-weight: 700; }

main { width: 100%; flex: 1; padding: 12px 14px 8px; }
.panel { display: block; }
.card { min-width: 0; margin: 0 0 10px; padding: 11px; border: 1px solid var(--grid); border-radius: 3px; background: var(--card); }
.card legend { padding: 0 7px; color: var(--text); font-weight: 700; }
.settings-grid { display: grid; grid-template-columns: 1.35fr repeat(3, 1fr) .8fr .85fr; gap: 12px; }
.settings-grid label, .bank-field { display: grid; gap: 5px; color: var(--text); font-size: 13px; }
input, select { width: 100%; height: 35px; padding: 0 9px; border: 1px solid #b9c8d2; border-radius: 2px; color: var(--text); background: white; }
input:focus, select:focus { outline: 2px solid rgba(0,166,166,.28); border-color: var(--accent); }
input[readonly] { background: #f2f6f8; color: var(--muted); }
.settings-note-row { margin-top: 9px; display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 12px; }

.import-row { display: grid; grid-template-columns: minmax(230px, 1.3fr) auto auto auto minmax(200px, 1.2fr) 160px; gap: 9px; align-items: end; }
.dropzone { min-height: 64px; padding: 9px 14px; display: grid; align-content: center; border: 1px dashed #8ba8b7; border-radius: 3px; color: #385567; background: #f5fafc; text-align: center; }
.dropzone.drag, .dropzone:hover { border-color: var(--accent); background: #e9f7f7; }
.dropzone input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.dropzone strong { font-size: 13px; }
.dropzone span { margin-top: 3px; color: var(--muted); font-size: 11px; }
.preview-box { min-height: 64px; padding: 8px; display: grid; place-items: center; align-content: center; border: 1px solid #aebdc7; background: #f8fbfd; text-align: center; }
.preview-box strong { font-size: 13px; }
.preview-box small { margin-top: 2px; color: var(--muted); font-size: 9px; }
.ocr-badge { margin-bottom: 4px; padding: 2px 6px; border-radius: 10px; color: #7a5a16; background: #fff0be; font-size: 8px; font-weight: 800; }
.ocr-badge.ready { color: #12633f; background: #d9f1e3; }
.import-foot { min-height: 25px; margin-top: 7px; display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.import-foot em { color: #8a35c9; font-size: 12px; white-space: nowrap; }
.file-list { flex: 1; display: flex; flex-wrap: wrap; gap: 6px; }
.file-item { padding: 4px 8px; display: flex; gap: 8px; border: 1px solid var(--grid); border-radius: 3px; background: #f8fbfd; font-size: 11px; }
.file-item span { color: var(--muted); }

.review-panel { min-width: 0; }
.toolbar { min-height: 46px; padding: 6px 0 8px; display: flex; align-items: center; gap: 6px; overflow-x: auto; }
.toolbar-spacer { flex: 1; }
.confirm { display: flex; align-items: center; gap: 5px; white-space: nowrap; font-size: 12px; }
.confirm input { width: 16px; height: 16px; accent-color: var(--accent); }
.validation-bar { margin-bottom: 6px; padding: 7px 10px; border: 1px solid var(--grid); color: var(--muted); background: #f7fafb; font-size: 12px; }
.validation-bar.good { color: #17603f; border-color: #b8dbc7; background: #e9f5ed; }
.validation-bar.bad { color: var(--danger); border-color: #e5c1c1; background: #fff1f1; }
.table-wrap { min-height: 350px; max-height: calc(100vh - 420px); overflow: auto; border: 1px solid var(--grid); background: var(--table); }
table { width: 100%; min-width: 1090px; border-collapse: collapse; }
th { position: sticky; top: 0; z-index: 2; height: 36px; padding: 7px 8px; border: 1px solid var(--grid); color: var(--text); background: var(--table-head); text-align: left; font-size: 12px; }
td { height: 37px; padding: 3px 5px; border: 1px solid #e0e8ed; background: var(--table); }
td:first-child { width: 42px; color: var(--muted); text-align: center; }
td input[type="text"], td input[type="date"], td input[type="number"] { height: 29px; border-color: transparent; background: transparent; }
td input:focus { background: white; }
td:nth-child(2) { width: 125px; }
td:nth-child(3) { min-width: 350px; }
td:nth-child(4) { width: 160px; }
td:nth-child(5), td:nth-child(6), td:nth-child(7) { width: 125px; }
td:nth-child(8), td:nth-child(9) { width: 58px; text-align: center; }
.delete-row { border: 0; color: var(--danger); background: transparent; font-size: 18px; }
.summary-row { min-height: 38px; display: flex; align-items: center; justify-content: space-between; gap: 20px; color: var(--muted); font-size: 12px; }
.totals { display: flex; gap: 24px; }
.totals strong { margin-left: 4px; color: var(--text); }

.status-bar { min-height: 38px; padding: 6px 14px; display: flex; align-items: center; justify-content: space-between; gap: 16px; color: var(--text); background: var(--status); font-size: 12px; }
.result { display: none; flex: 1; padding: 4px 8px; color: #12633f; text-align: center; }
.result.show { display: block; }
.result.error { color: var(--danger); }

.processing-overlay[hidden] { display: none; }
.processing-overlay { position: fixed; inset: 0; z-index: 1000; padding: 20px; display: grid; place-items: center; background: rgba(9, 28, 42, .66); backdrop-filter: blur(3px); }
.processing-dialog { width: min(520px, 100%); padding: 30px 32px 26px; border: 1px solid #b9cbd6; border-radius: 8px; background: white; box-shadow: 0 24px 80px rgba(0, 20, 34, .36); text-align: center; }
.working-spinner { width: 52px; height: 52px; margin: 0 auto 15px; border: 5px solid #d9e7ec; border-top-color: var(--accent); border-radius: 50%; animation: working-spin .8s linear infinite; }
.processing-kicker { margin: 0 0 7px; color: #087f83; font-size: 11px; font-weight: 800; letter-spacing: .14em; }
.processing-dialog h2 { margin: 0; color: var(--brand); font-size: 23px; }
.processing-file { max-width: 100%; margin-top: 12px; display: block; overflow: hidden; color: var(--text); text-overflow: ellipsis; white-space: nowrap; }
.processing-dialog > p:not(.processing-kicker):not(.processing-time) { min-height: 42px; margin: 12px 0; color: var(--muted); line-height: 1.5; }
.processing-track { height: 7px; margin: 18px 0 8px; overflow: hidden; border-radius: 10px; background: #dfe9ee; }
.processing-track span { width: 42%; height: 100%; display: block; border-radius: inherit; background: var(--accent); animation: working-slide 1.35s ease-in-out infinite; }
.processing-time { margin: 0; color: var(--muted); font-size: 11px; }
.processing-actions { margin-top: 22px; display: flex; justify-content: center; gap: 10px; }
.cancel-button { color: white; border-color: #aa3c3c; background: #b94343; }
.cancel-button:hover { background: #9d3434; }
.processing-actions button:disabled { opacity: .55; cursor: not-allowed; }
@keyframes working-spin { to { transform: rotate(360deg); } }
@keyframes working-slide { 0% { transform: translateX(-110%); } 55% { transform: translateX(140%); } 100% { transform: translateX(260%); } }
@media (prefers-reduced-motion: reduce) { .working-spinner, .processing-track span { animation-duration: 2.5s; } }

@media (max-width: 1100px) {
  .app-header { align-items: flex-start; flex-direction: column; }
  .header-actions { width: 100%; justify-content: flex-start; flex-wrap: wrap; }
  .settings-grid { grid-template-columns: repeat(3, 1fr); }
  .import-row { grid-template-columns: 1fr repeat(3, auto); }
  .dropzone { grid-column: 1 / 4; }
  .preview-box { grid-column: 4; grid-row: 1 / 3; }
  .table-wrap { max-height: 440px; }
}

@media (max-width: 680px) {
  .title-block h1 { font-size: 20px; }
  .connection { width: 100%; }
  main { padding-inline: 7px; }
  .settings-grid { grid-template-columns: 1fr 1fr; }
  .settings-note-row, .import-foot, .summary-row, .status-bar { align-items: flex-start; flex-direction: column; }
  .import-row { grid-template-columns: 1fr 1fr; }
  .bank-field, .dropzone { grid-column: 1 / 3; }
  .preview-box { grid-column: 2; grid-row: auto; }
  .tall-button { min-height: 42px; }
  .toolbar-spacer { display: none; }
  .import-foot em { white-space: normal; }
  .totals { flex-wrap: wrap; gap: 12px; }
  .processing-dialog { padding: 25px 18px 20px; }
  .processing-actions { flex-direction: column; }
}
