:root {
    color-scheme: light;
    --navy: #102a43;
    --navy-soft: #1d3c57;
    --teal: #0a9c91;
    --teal-dark: #087e77;
    --ink: #172b3a;
    --muted: #728394;
    --line: #e4ebf0;
    --paper: #ffffff;
    --wash: #f4f7f9;
    --amber: #d98b18;
    --red: #cc5252;
    --shadow: 0 18px 50px rgba(16, 42, 67, .08);
    font-family: "Segoe UI", Arial, sans-serif;
    font-synthesis: none;
    text-rendering: optimizeLegibility;
    -webkit-tap-highlight-color: transparent;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--wash); touch-action: manipulation; }
body { margin: 0; color: var(--ink); background: var(--wash); min-height: 100vh; }
button, input, select, textarea { font: inherit; }
button { touch-action: manipulation; }
[hidden] { display: none !important; }

.app-frame { min-height: 100vh; display: flex; flex-direction: column; }
.topbar { height: 76px; padding: 0 clamp(18px, 5vw, 72px); background: var(--paper); border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; }
.brand { display: inline-flex; align-items: center; gap: 11px; text-decoration: none; color: var(--navy); }
.brand img { border-radius: 12px; }
.brand strong, .brand small { display: block; }
.brand strong { font: 800 17px "Segoe UI", Arial, sans-serif; letter-spacing: -.04em; }
.brand small { margin-top: 1px; color: var(--muted); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }
.topbar-actions { display: flex; align-items: center; gap: 13px; }
.connection-pill { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.connection-pill i { width: 8px; height: 8px; border-radius: 99px; background: #c5d0d7; }
.connection-pill.is-online i { background: #22ad89; box-shadow: 0 0 0 3px #e0f4ed; }
.connection-pill.is-offline i { background: #e5a23e; box-shadow: 0 0 0 3px #fbf0dd; }

.main-area { width: min(1220px, calc(100% - 44px)); margin: 0 auto; flex: 1; }
.login-layout { min-height: calc(100vh - 126px); padding: 62px 0; display: grid; grid-template-columns: 1.1fr .9fr; align-items: center; gap: clamp(44px, 8vw, 112px); }
.login-promo { max-width: 550px; padding: 8px 0; }
.eyebrow { color: var(--teal-dark); font-size: 11px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; }
.login-promo h1 { margin: 17px 0 18px; color: var(--navy); font: 800 clamp(38px, 5vw, 62px)/1.08 "Segoe UI", Arial, sans-serif; letter-spacing: -.065em; }
.login-promo > p { max-width: 465px; margin: 0; color: var(--muted); font-size: 16px; line-height: 1.8; }
.login-feature { display: flex; align-items: center; gap: 15px; margin-top: 28px; }
.login-feature > span { display: grid; place-items: center; width: 40px; height: 40px; color: var(--teal-dark); border: 1px solid #d5eae7; border-radius: 13px; font-size: 11px; font-weight: 700; }
.login-feature strong, .login-feature small { display: block; }
.login-feature strong { color: var(--navy); font-size: 13px; }
.login-feature small { margin-top: 4px; color: var(--muted); font-size: 12px; }
.login-card, .setup-card { width: min(100%, 430px); margin: 0 auto; padding: 36px; background: var(--paper); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow); }
.login-card > img, .setup-card > img { margin-bottom: 24px; border-radius: 16px; }
.login-card h2, .setup-card h1 { margin: 8px 0; color: var(--navy); font: 800 25px "Segoe UI", Arial, sans-serif; letter-spacing: -.04em; }
.login-card > p, .setup-card > p { color: var(--muted); font-size: 13px; line-height: 1.65; }
.login-card form, .setup-card form { margin-top: 24px; }
label { display: block; margin-bottom: 14px; color: #40566a; font-size: 12px; font-weight: 600; }
input, select, textarea { width: 100%; min-height: 44px; margin-top: 7px; padding: 10px 12px; color: var(--ink); background: #fbfcfd; border: 1px solid #dce5eb; border-radius: 10px; outline: 0; transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus, textarea:focus { border-color: #6cc5bb; box-shadow: 0 0 0 3px rgba(10, 156, 145, .11); }
input[type="file"] { padding: 8px; font-size: 12px; }
textarea { min-height: 88px; resize: vertical; }
.button { display: inline-flex; min-height: 42px; align-items: center; justify-content: center; gap: 8px; padding: 0 16px; border: 1px solid transparent; border-radius: 10px; cursor: pointer; font-size: 13px; font-weight: 700; text-decoration: none; transition: transform .15s, background .15s, border-color .15s; }
.button:hover { transform: translateY(-1px); }
.button:disabled { cursor: wait; opacity: .65; transform: none; }
.button-primary { color: #fff; background: var(--teal); box-shadow: 0 7px 16px rgba(10, 156, 145, .18); }
.button-primary:hover { background: var(--teal-dark); }
.button-outline { color: var(--navy); background: #fff; border-color: var(--line); }
.button-outline:hover, .button-quiet:hover { background: #f2f6f8; }
.button-quiet { min-height: 38px; padding: 0 11px; color: #536779; background: transparent; }
.button-wide { width: 100%; margin-top: 9px; }
.offline-hint { margin: 18px 0 0 !important; font-size: 11px !important; }
.notice { padding: 11px 13px; border-radius: 9px; font-size: 12px; line-height: 1.5; }
.notice-error { color: #9a3434; background: #fff1f0; border: 1px solid #f5d5d2; }
.setup-page { display: grid; place-items: center; padding: 22px; }
.setup-card { max-width: 440px; }
.setup-card form .button { width: 100%; }

.app-screen { padding: 37px 0 24px; }
.welcome-row { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.welcome-row h1 { margin: 8px 0 4px; color: var(--navy); font: 800 clamp(24px, 3vw, 32px) "Segoe UI", Arial, sans-serif; letter-spacing: -.05em; }
.welcome-row p { margin: 0; color: var(--muted); font-size: 13px; }
.summary-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin: 28px 0; }
.summary-card { display: flex; align-items: center; gap: 14px; min-height: 91px; padding: 17px; background: var(--paper); border: 1px solid var(--line); border-radius: 15px; }
.summary-icon { display: grid; place-items: center; flex: 0 0 auto; width: 40px; height: 40px; border-radius: 12px; font-size: 14px; font-weight: 800; }
.icon-machine { color: #167c8b; background: #e6f4f5; }
.icon-driver { color: #6c5ab3; background: #f0edfb; }
.icon-service { color: #af7921; background: #fbf3e4; }
.icon-alert { color: #c25353; background: #fceceb; }
.summary-card span:not(.summary-icon) { display: block; color: var(--muted); font-size: 11px; }
.summary-card strong { display: block; margin-top: 3px; color: var(--navy); font: 800 22px "Segoe UI", Arial, sans-serif; }
.sync-notice { margin: 0 0 20px; padding: 12px 15px; color: #5b6770; background: #fff9ed; border: 1px solid #f2e4c9; border-radius: 10px; font-size: 12px; }
.sync-notice.is-error { color: #9a3434; background: #fff1f0; border-color: #f5d5d2; }
.sync-notice.is-ok { color: #177261; background: #eaf7f3; border-color: #d0ece2; }
.section-tabs { display: flex; gap: 7px; border-bottom: 1px solid var(--line); }
.section-tab { position: relative; display: inline-flex; align-items: center; gap: 8px; min-height: 47px; padding: 0 15px; color: var(--muted); background: transparent; border: 0; cursor: pointer; font-size: 13px; font-weight: 700; }
.section-tab.is-active { color: var(--navy); }
.section-tab.is-active::after { position: absolute; right: 12px; bottom: -1px; left: 12px; height: 2px; content: ""; background: var(--teal); border-radius: 3px 3px 0 0; }
.section-tab span { display: grid; place-items: center; min-width: 22px; height: 22px; padding: 0 6px; color: #63798b; background: #edf2f5; border-radius: 20px; font-size: 10px; }
.list-panel { min-height: 285px; padding: 22px 0 10px; }
.list-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 19px; }
.list-toolbar h2 { margin: 0; color: var(--navy); font: 800 19px "Segoe UI", Arial, sans-serif; letter-spacing: -.035em; }
.list-toolbar p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.toolbar-actions { display: flex; align-items: center; gap: 9px; }
.search-field { display: flex; align-items: center; gap: 8px; width: 218px; height: 40px; margin: 0; padding: 0 11px; color: #7e8d9a; background: #fff; border: 1px solid var(--line); border-radius: 9px; }
.search-field input { min-height: 0; margin: 0; padding: 0; background: transparent; border: 0; box-shadow: none !important; font-size: 12px; }
.record-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.record-card { position: relative; min-width: 0; padding: 17px; background: var(--paper); border: 1px solid var(--line); border-radius: 15px; box-shadow: 0 4px 14px rgba(16, 42, 67, .025); }
.record-head { display: flex; align-items: flex-start; gap: 13px; }
.record-avatar { display: grid; place-items: center; flex: 0 0 auto; width: 48px; height: 48px; overflow: hidden; color: var(--teal-dark); background: #e6f4f2; border-radius: 13px; font-weight: 800; }
.record-avatar img { width: 100%; height: 100%; object-fit: cover; }
.record-title { flex: 1; min-width: 0; }
.record-title h3 { overflow: hidden; margin: 1px 0 4px; color: var(--navy); font-size: 15px; text-overflow: ellipsis; white-space: nowrap; }
.record-title p { margin: 0; color: var(--muted); font-size: 11px; }
.record-tag { flex: 0 0 auto; padding: 5px 8px; color: #557084; background: #f0f4f6; border-radius: 20px; font-size: 10px; font-weight: 700; }
.record-details { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 16px 0 0; padding-top: 14px; border-top: 1px solid #edf1f4; }
.detail-item span, .detail-item strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.detail-item span { margin-bottom: 4px; color: #8a98a4; font-size: 10px; }
.detail-item strong { color: #354d60; font-size: 11px; font-weight: 600; }
.expiry-warning { color: var(--amber) !important; }
.expiry-danger { color: var(--red) !important; }
.record-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 15px; }
.small-button { min-height: 32px; padding: 0 9px; color: #476074; background: #f5f8f9; border: 1px solid #e8eef1; border-radius: 8px; cursor: pointer; font-size: 10px; font-weight: 700; }
.small-button:hover { color: var(--teal-dark); border-color: #bfe2dd; background: #eef9f6; }
.small-button.is-danger { color: #a44b4b; }
.empty-state { grid-column: 1 / -1; display: grid; place-items: center; min-height: 220px; padding: 30px; color: var(--muted); text-align: center; background: rgba(255,255,255,.65); border: 1px dashed #d9e2e8; border-radius: 15px; }
.empty-state strong { display: block; margin-bottom: 6px; color: var(--navy); font-size: 15px; }
.app-footer { display: flex; justify-content: space-between; gap: 14px; padding: 15px 0 3px; color: var(--muted); border-top: 1px solid var(--line); font-size: 11px; }
.text-button { color: var(--teal-dark); background: none; border: 0; cursor: pointer; font-size: 11px; font-weight: 700; }
.site-footer { display: flex; justify-content: space-between; padding: 18px clamp(18px, 5vw, 72px); color: #98a5ae; background: #fff; border-top: 1px solid var(--line); font-size: 10px; }
.swal2-popup { border-radius: 18px !important; }
.swal-form { max-height: min(62vh, 580px); overflow: auto; padding: 3px 2px; text-align: left; }
.swal-form label { margin-bottom: 8px; }
.swal-form .form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.swal-form .file-note { display: block; margin-top: -4px; color: var(--muted); font-size: 10px; }
.swal-form .existing-file { display: block; margin: -3px 0 9px; color: var(--teal-dark); font-size: 11px; }
.history-list, .document-list { max-height: 36vh; overflow: auto; margin: 0 0 16px; }
.history-row, .document-row { display: flex; justify-content: space-between; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--line); text-align: left; }
.history-row strong, .document-row strong { display: block; color: var(--navy); font-size: 12px; }
.history-row small, .document-row small { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; }
.swal2-html-container .button { margin-top: 9px; }

@media (max-width: 850px) {
    .login-layout { grid-template-columns: .9fr 1.1fr; gap: 35px; }
    .summary-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 650px) {
    .topbar { height: 64px; padding: 0 16px; }
    .topbar-actions { gap: 5px; }
    .connection-pill { font-size: 0; }
    .connection-pill i { width: 9px; height: 9px; }
    .main-area { width: min(100% - 28px, 540px); }
    .login-layout { min-height: calc(100vh - 112px); grid-template-columns: 1fr; gap: 28px; padding: 30px 0; }
    .login-promo { padding: 6px 2px 0; }
    .login-promo h1 { margin: 12px 0 10px; font-size: 38px; }
    .login-promo > p { font-size: 13px; line-height: 1.65; }
    .login-feature { display: none; }
    .login-card { width: 100%; padding: 25px; border-radius: 18px; }
    .login-card > img { width: 45px; height: 45px; margin-bottom: 18px; }
    .app-screen { padding: 25px 0 18px; }
    .welcome-row { align-items: flex-start; }
    .welcome-row h1 { font-size: 24px; }
    .welcome-row p { max-width: 250px; line-height: 1.5; }
    .welcome-row > .button { flex: 0 0 auto; min-height: 38px; padding: 0 10px; font-size: 11px; }
    .summary-grid { gap: 9px; margin: 20px 0; }
    .summary-card { min-height: 75px; gap: 9px; padding: 11px; border-radius: 12px; }
    .summary-icon { width: 33px; height: 33px; border-radius: 10px; }
    .summary-card span:not(.summary-icon) { font-size: 9px; }
    .summary-card strong { font-size: 19px; }
    .list-toolbar { align-items: flex-start; flex-direction: column; }
    .toolbar-actions { width: 100%; }
    .search-field { flex: 1; width: auto; }
    .record-grid { grid-template-columns: 1fr; gap: 10px; }
    .record-card { padding: 14px; }
    .section-tab { padding: 0 10px; }
    .app-footer { font-size: 10px; }
    .site-footer { padding: 15px; }
}
@media (max-width: 380px) {
    .welcome-row { flex-direction: column; }
    .welcome-row > .button { align-self: flex-start; }
    .login-card { padding: 21px; }
}
