:root {
  --font-sans: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --ink: #19231f;
  --muted: #66716c;
  --paper: #f5f5ef;
  --surface: #ffffff;
  --line: #dfe2da;
  --green: #155e47;
  --green-deep: #0d4635;
  --mint: #dff0e8;
  --amber: #d9a441;
  --danger: #a33c36;
  --interactive-hover: #eef4f0;
  --interactive-border-hover: #a7b7ad;
  --focus-ring: rgba(21, 94, 71, .18);
  --shadow: 0 18px 50px rgba(25, 35, 31, .08);
  --radius: 18px;
}

* { box-sizing: border-box; }
html { background: var(--paper); color: var(--ink); font-family: var(--font-sans); }
body { margin: 0; min-height: 100vh; }
a { color: inherit; }
button, input, select, textarea { font: inherit; }
input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="button"]):not([type="submit"]):not([type="reset"]), textarea { font-weight: 400; }
button, a { -webkit-tap-highlight-color: transparent; }

.topbar { height: 72px; padding: 0 40px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; border-bottom: 1px solid var(--line); background: rgba(245, 245, 239, .94); position: sticky; top: 0; z-index: 20; backdrop-filter: blur(18px); }
.brand { display: inline-flex; gap: 10px; align-items: center; width: max-content; font-weight: 760; text-decoration: none; letter-spacing: -.02em; transition: color .16s ease; }
.brand:hover { color: var(--green); }
.brand-mark { width: 32px; height: 32px; border-radius: 10px 10px 10px 3px; display: inline-grid; place-items: center; background: var(--green); color: white; font-family: var(--font-sans); font-weight: 700; transition: background-color .16s ease, transform .16s ease; }
.brand:hover .brand-mark { background: var(--green-deep); transform: translateY(-1px); }
.brand-mark-large { width: 46px; height: 46px; font-size: 22px; border-radius: 14px 14px 14px 4px; }
.main-nav { display: flex; gap: 8px; }
.main-nav a { padding: 10px 14px; border-radius: 10px; color: var(--muted); text-decoration: none; font-size: 14px; font-weight: 650; transition: background-color .16s ease, color .16s ease; }
.main-nav a:hover { background: var(--interactive-hover); color: var(--green-deep); }
.account-menu { display: flex; align-items: center; justify-self: end; gap: 14px; font-size: 14px; }
.account-menu > a { padding: 7px 9px; border-radius: 9px; font-weight: 650; text-decoration: none; transition: background-color .16s ease, color .16s ease; }
.account-menu > a:hover { background: var(--interactive-hover); color: var(--green-deep); }

.page-shell { width: min(1180px, calc(100% - 48px)); margin: 0 auto; padding: 54px 0 88px; }
.narrow-page { width: min(680px, 100%); margin: 0 auto; }
.page-heading { margin-bottom: 32px; }
.page-heading h1, .dashboard-heading h1 { margin: 4px 0 9px; font-family: var(--font-sans); font-size: clamp(34px, 5vw, 50px); font-weight: 500; letter-spacing: -.035em; line-height: 1.04; }
.page-heading > p:last-child, .dashboard-heading > div > p:last-child { color: var(--muted); max-width: 680px; font-size: 17px; }
.eyebrow { margin: 0; color: var(--green); font-size: 12px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.dashboard-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; padding-bottom: 38px; border-bottom: 1px solid var(--line); }
.section-block { margin-top: 46px; }
.section-title { display: flex; align-items: end; justify-content: space-between; margin-bottom: 20px; }
.section-title h2 { margin: 4px 0 0; font-family: var(--font-sans); font-size: 28px; font-weight: 500; }

.surface, .handler-card, .form-card { background: var(--surface); border: 1px solid rgba(25,35,31,.08); border-radius: var(--radius); box-shadow: var(--shadow); }
.handler-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.handler-card { min-height: 260px; position: relative; overflow: hidden; display: flex; flex-direction: column; transition: border-color .18s ease, box-shadow .18s ease, transform .18s ease; }
.handler-card:hover { border-color: var(--interactive-border-hover); box-shadow: 0 22px 56px rgba(25,35,31,.13); transform: translateY(-3px); }
.handler-card:focus-within { border-color: var(--green); box-shadow: 0 0 0 3px var(--focus-ring), var(--shadow); }
.handler-card-link { min-height: 260px; padding: 22px; display: flex; flex: 1; flex-direction: column; color: inherit; text-decoration: none; outline: none; }
.handler-icon { width: 48px; height: 48px; overflow: hidden; display: grid; flex: 0 0 auto; place-items: center; border-radius: 15px; background: var(--mint); color: var(--green); font-family: var(--font-sans); font-size: 24px; }
.handler-icon img { width: 100%; height: 100%; display: block; object-fit: cover; }
.handler-body { flex: 1; }
.handler-meta { margin-top: 24px; display: flex; color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.handler-card h3 { margin: 10px 0 8px; font-size: 21px; letter-spacing: -.02em; }
.handler-card p { color: var(--muted); line-height: 1.52; }
.handler-capabilities { min-height: 58px; margin-top: 18px; padding-top: 14px; display: flex; align-items: center; justify-content: space-between; gap: 14px; border-top: 1px solid var(--line); }
.handler-file-types { display: flex; align-items: center; gap: 5px; }
.file-type-icon { width: 40px; height: 48px; display: block; overflow: visible; }
.file-type-paper { fill: #e4e7e8; }
.file-type-fold { fill: #b8bec3; }
.file-type-label { fill: #727a80; }
.file-type-icon text { fill: white; font-family: var(--font-sans); font-size: 8px; font-weight: 750; letter-spacing: .02em; }
.file-type-icon-pdf .file-type-label { fill: #e85245; }
.file-type-icon-excel .file-type-label { fill: #29865f; }
.file-type-icon-txt .file-type-label { fill: #747c82; }
.handler-file-count { min-width: 58px; padding: 7px 10px; border-radius: 999px; background: #eef1ed; color: var(--muted); font-size: 12px; font-weight: 750; text-align: center; white-space: nowrap; }
.handler-card-favorite { position: absolute; z-index: 2; top: 17px; right: 15px; }
.favorite-button { width: 40px; height: 40px; padding: 0; border: 0; border-radius: 10px; background: transparent; color: var(--amber); font-size: 28px; cursor: pointer; transition: background-color .16s ease, color .16s ease, transform .16s ease; }
.favorite-button:hover { background: #fff7e5; color: #b77f13; transform: scale(1.05); }
.favorite-button:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }

.button { display: inline-flex; min-height: 42px; padding: 0 17px; justify-content: center; align-items: center; border: 1px solid transparent; border-radius: 11px; font-weight: 720; font-size: 14px; text-decoration: none; cursor: pointer; transition: background-color .16s ease, border-color .16s ease, color .16s ease, box-shadow .16s ease, transform .16s ease; }
.button-primary { background: var(--green); color: white; }
.button-primary:hover { background: var(--green-deep); box-shadow: 0 7px 18px rgba(13,70,53,.18); transform: translateY(-1px); }
.button-secondary { background: var(--surface); border-color: var(--line); color: var(--ink); }
.button-danger { background: #fff1ef; border-color: #e4bbb7; color: var(--danger); }
.button-ghost { background: transparent; border-color: var(--line); }
.button-secondary:hover, .button-ghost:hover { border-color: var(--interactive-border-hover); background: var(--interactive-hover); color: var(--green-deep); box-shadow: 0 6px 16px rgba(25,35,31,.07); transform: translateY(-1px); }
.button-danger:hover { border-color: #d49791; background: #fde5e2; color: #842e29; box-shadow: 0 6px 16px rgba(163,60,54,.11); transform: translateY(-1px); }
.button:active { box-shadow: none; transform: translateY(0); }
.button:disabled { opacity: .55; cursor: not-allowed; box-shadow: none; transform: none; }
.button-small { min-height: 34px; padding: 0 12px; font-size: 12px; }
.button-wide { width: 100%; min-height: 48px; }

.empty-state { grid-column: 1 / -1; padding: 48px; border: 1px dashed #bdc7c0; border-radius: var(--radius); text-align: center; }
.empty-state h3 { margin: 10px 0 6px; }
.empty-state p { color: var(--muted); margin: 0 auto 22px; }
.empty-icon { color: var(--amber); font-size: 38px; }
.table-wrap { overflow: hidden; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 15px 18px; text-align: left; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; }
tbody tr:last-child td { border-bottom: 0; }
.compact-empty { padding: 28px; color: var(--muted); }
.status { display: inline-flex; padding: 5px 9px; border-radius: 999px; background: #edf0eb; font-size: 12px; font-weight: 750; }

.login-shell { min-height: 100vh; padding: 32px; display: grid; place-items: center; }
.login-form-wrap { width: min(430px, 100%); }
.form-card { width: min(430px, 100%); padding: 38px; box-shadow: none; }
.form-heading { margin-bottom: 28px; }
.form-heading h2 { margin: 7px 0 8px; font-family: var(--font-sans); font-size: 34px; font-weight: 500; }
.form-stack { display: grid; gap: 18px; padding: 28px; }
.field { display: grid; gap: 8px; margin-bottom: 18px; font-size: 13px; font-weight: 700; }
.field input, .field select, .field textarea { width: 100%; min-height: 46px; padding: 10px 13px; border: 1px solid #cfd5cf; border-radius: 10px; background: #fbfcf9; color: var(--ink); outline: none; transition: background-color .16s ease, border-color .16s ease, box-shadow .16s ease; }
.field input:hover:not(:disabled), .field select:hover:not(:disabled), .field textarea:hover:not(:disabled) { border-color: var(--interactive-border-hover); background: var(--surface); box-shadow: 0 3px 10px rgba(25,35,31,.04); }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--green); background: var(--surface); box-shadow: 0 0 0 3px var(--focus-ring); }
.field small, .muted { color: var(--muted); font-weight: 400; }
.field textarea { resize: vertical; }
.check-field { display: flex; align-items: center; gap: 10px; font-weight: 650; cursor: pointer; transition: color .16s ease; }
.check-field:hover { color: var(--green-deep); }
.check-field input { width: 18px; height: 18px; accent-color: var(--green); cursor: pointer; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.split-row { padding: 24px; display: flex; align-items: center; justify-content: space-between; gap: 22px; }
.split-row p { margin: 6px 0 0; }

.flash-stack { display: grid; gap: 10px; margin-bottom: 22px; }
.login-shell .flash-stack { position: fixed; z-index: 30; top: 20px; left: 50%; transform: translateX(-50%); width: min(520px, calc(100% - 32px)); }
.flash { padding: 13px 16px; border-radius: 11px; border: 1px solid; background: white; font-size: 14px; box-shadow: var(--shadow); }
.flash-error { color: #7b2925; border-color: #efc3bf; background: #fff1ef; }
.flash-success { color: var(--green-deep); border-color: #b6d9c9; background: #eef9f3; }
.flash-warning { color: #70500e; border-color: #e7d098; background: #fff8e5; }
.error-page { padding: 100px 0; text-align: center; }
.error-code { margin: 0; color: var(--green); font-family: var(--font-sans); font-size: 72px; }
.error-page h1 { margin: 0 0 26px; }
.toolbar { margin: 28px 0 16px; display: flex; gap: 10px; }
.toolbar input { min-height: 42px; flex: 1; padding: 0 13px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); outline: none; transition: background-color .16s ease, border-color .16s ease, box-shadow .16s ease; }
.toolbar input:hover { border-color: var(--interactive-border-hover); box-shadow: 0 3px 10px rgba(25,35,31,.04); }
.toolbar input:focus { border-color: var(--green); box-shadow: 0 0 0 3px var(--focus-ring); }
.text-link { min-height: 32px; padding: 0 7px; display: inline-flex; align-items: center; border-radius: 8px; color: var(--green); font-weight: 700; text-decoration: none; transition: background-color .16s ease, color .16s ease; }
.text-link:hover { background: var(--interactive-hover); color: var(--green-deep); }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.detail-card { padding: 26px; }
.detail-card h2 { margin: 9px 0; font-family: var(--font-sans); font-weight: 500; font-size: 30px; }
.inline-form { padding: 22px; display: flex; align-items: end; gap: 14px; }
.inline-form .field { margin: 0; }
.grow { flex: 1; }
.danger-zone { padding: 24px; border: 1px solid #e4bbb7; border-radius: var(--radius); background: #fff9f8; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.danger-zone h2 { margin: 0 0 6px; font-size: 19px; }
.danger-zone p { margin: 0; color: var(--muted); }
.client-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.client-card { min-height: 94px; padding: 18px; display: flex; align-items: center; gap: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 15px; text-decoration: none; }
.client-card:hover { border-color: #aab8af; box-shadow: var(--shadow); }
.client-avatar { width: 50px; height: 50px; display: grid; place-items: center; border-radius: 14px; background: var(--mint); color: var(--green); font-family: var(--font-sans); font-size: 22px; }
.client-card-body { display: grid; gap: 5px; flex: 1; }
.client-card-body small { color: var(--muted); }
.connection-dot { width: 10px; height: 10px; border-radius: 50%; background: #c6cbc7; box-shadow: 0 0 0 4px #f0f1ee; }
.connection-dot.connected { background: #29966e; box-shadow: 0 0 0 4px #e2f3eb; }
.security-note { padding: 15px 17px; border-radius: 12px; background: var(--mint); color: var(--green-deep); }
.security-note p { margin: 5px 0 0; font-size: 13px; }
.status-success { color: var(--green-deep); background: var(--mint); }
.status-failed { color: var(--danger); background: #fff1ef; }
.status-warning { color: #70500e; background: #fff5d8; }
.handler-availability { align-items: flex-start; padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: #fbfcf9; transition: background-color .16s ease, border-color .16s ease, box-shadow .16s ease; }
.handler-availability:hover { border-color: var(--interactive-border-hover); background: var(--interactive-hover); }
.handler-availability:has(input:focus-visible) { border-color: var(--green); box-shadow: 0 0 0 3px var(--focus-ring); }
.handler-availability > span { display: grid; gap: 5px; }
.handler-availability small { color: var(--muted); font-size: 12px; font-weight: 400; line-height: 1.45; }
.handler-icon-editor { margin: 0; padding: 18px; display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 14px 18px; border: 1px solid var(--line); border-radius: 12px; }
.handler-icon-editor legend { padding: 0 6px; font-size: 13px; font-weight: 700; }
.handler-icon-editor .field { margin: 0; }
.handler-icon-editor .check-field { grid-column: 2; }
.handler-icon-preview { width: 64px; height: 64px; border-radius: 18px; font-size: 28px; }
.handler-setting-group { margin: 0; padding: 18px; border: 1px solid var(--line); border-radius: 12px; }
.handler-setting-group > legend { padding: 0 6px; font-size: 13px; font-weight: 700; }
.handler-setting-group > small { display: block; margin-top: 11px; color: var(--muted); font-size: 12px; line-height: 1.45; }
.file-type-selector { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.file-type-option, .file-mode-option { position: relative; cursor: pointer; }
.file-type-option > input, .file-mode-option > input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.file-type-option-surface { min-height: 76px; padding: 10px 12px; display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 11px; background: #fbfcf9; transition: background-color .16s ease, border-color .16s ease, box-shadow .16s ease, transform .16s ease; }
.file-type-option:hover .file-type-option-surface { border-color: var(--interactive-border-hover); background: var(--interactive-hover); transform: translateY(-1px); }
.file-type-option > input:checked + .file-type-option-surface { border-color: #77a994; background: #edf7f2; box-shadow: inset 0 0 0 1px #77a994; }
.file-type-option > input:focus-visible + .file-type-option-surface { outline: 3px solid var(--focus-ring); outline-offset: 2px; }
.file-type-option .file-type-icon { width: 40px; height: 48px; }
.file-type-option strong { font-size: 13px; }
.file-mode-selector { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.file-mode-option > span { min-height: 68px; padding: 13px 14px; display: grid; align-content: center; gap: 4px; border: 1px solid var(--line); border-radius: 11px; background: #fbfcf9; transition: background-color .16s ease, border-color .16s ease, box-shadow .16s ease, transform .16s ease; }
.file-mode-option:hover > span { border-color: var(--interactive-border-hover); background: var(--interactive-hover); transform: translateY(-1px); }
.file-mode-option > input:checked + span { border-color: #77a994; background: #edf7f2; box-shadow: inset 0 0 0 1px #77a994; }
.file-mode-option > input:focus-visible + span { outline: 3px solid var(--focus-ring); outline-offset: 2px; }
.file-mode-option strong { font-size: 13px; }
.file-mode-option small { color: var(--muted); font-size: 12px; font-weight: 400; }

:where(.brand, .main-nav a, .account-menu > a, .button, .text-link):focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }
.check-field input:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  .brand, .brand-mark, .main-nav a, .account-menu > a, .button, .text-link,
  .field input, .field select, .field textarea, .toolbar input,
  .check-field, .handler-availability, .handler-card, .favorite-button,
  .file-type-option-surface, .file-mode-option > span { transition: none; }
}
@media (max-width: 900px) {
  .handler-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar { padding: 0 20px; grid-template-columns: 1fr auto; }
  .main-nav { display: none; }
}

@media (max-width: 620px) {
  .page-shell { width: min(100% - 28px, 1180px); padding-top: 34px; }
  .handler-grid { grid-template-columns: 1fr; }
  .client-grid, .detail-grid { grid-template-columns: 1fr; }
  .dashboard-heading { align-items: start; flex-direction: column; }
  .login-shell { padding: 18px; }
  .form-card { padding: 28px 22px; }
  .account-menu > a { display: none; }
  th:nth-child(2), td:nth-child(2) { display: none; }
  .danger-zone, .inline-form { align-items: stretch; flex-direction: column; }
  .handler-icon-editor { grid-template-columns: 1fr; }
  .handler-icon-editor .check-field { grid-column: 1; }
  .file-type-selector, .file-mode-selector { grid-template-columns: 1fr; }
}
