:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #172033;
  --muted: #667085;
  --line: #d8dde6;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --danger: #b42318;
  --warn: #b54708;
  --ok: #027a48;
  --nav: #111827;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
.app-shell { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.sidebar { background: var(--nav); color: #fff; padding: 18px 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; gap: 12px; align-items: center; }
.brand-mark { width: 42px; height: 42px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; color: #fff; font-weight: 700; }
.brand strong { display: block; font-size: 16px; }
.brand span { display: block; color: #b7c0ce; font-size: 12px; margin-top: 2px; }
.nav { margin-top: 22px; display: grid; gap: 4px; }
.nav a { color: #d9dee8; padding: 10px 12px; border-radius: 6px; font-size: 14px; }
.nav a:hover, .nav a.active { background: rgba(255,255,255,.1); color: #fff; text-decoration: none; }
.main { min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 18px 26px; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar h1 { margin: 0; font-size: 24px; letter-spacing: 0; }
.userbar { display: flex; gap: 12px; align-items: center; color: var(--muted); }
.content { padding: 22px 26px 42px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 18px; margin-bottom: 18px; }
.panel h2, .panel h3 { margin-top: 0; letter-spacing: 0; }
.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)); }
.stat { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 16px; }
.stat span { display: block; color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.stat strong { font-size: 24px; letter-spacing: 0; }
.toolbar { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.button, button { display: inline-flex; justify-content: center; align-items: center; min-height: 38px; padding: 8px 13px; border-radius: 6px; border: 1px solid var(--line); background: #fff; color: var(--text); cursor: pointer; font-size: 14px; text-decoration: none; }
.button:hover, button:hover { text-decoration: none; background: #f8fafc; }
.button.primary, button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.button.primary:hover, button.primary:hover { background: var(--accent-dark); }
.button.danger, button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.button.ghost { background: transparent; color: inherit; }
.button.small { min-height: 30px; padding: 5px 9px; font-size: 12px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: #f8fafc; color: #344054; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
tr:last-child td { border-bottom: 0; }
.num { text-align: right; white-space: nowrap; }
.muted { color: var(--muted); }
.badge { display: inline-flex; align-items: center; min-height: 24px; padding: 3px 8px; border-radius: 999px; background: #eef2f6; color: #344054; font-size: 12px; }
.badge.ok { background: #dcfae6; color: var(--ok); }
.badge.warn { background: #fef0c7; color: var(--warn); }
.badge.danger { background: #fee4e2; color: var(--danger); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .full, .full { grid-column: 1 / -1; }
label { display: grid; gap: 6px; color: #344054; font-size: 13px; }
input, select, textarea { width: 100%; min-height: 38px; border: 1px solid #cfd6e2; border-radius: 6px; padding: 8px 10px; font: inherit; background: #fff; color: var(--text); }
input[type="checkbox"], input[type="radio"] { width: 18px; min-width: 18px; min-height: 18px; padding: 0; margin: 0; accent-color: var(--accent); }
label.checkline { display: flex; align-items: center; gap: 10px; min-height: 38px; line-height: 1.35; cursor: pointer; }
label.checkline span { color: #344054; }
textarea { min-height: 90px; resize: vertical; }
.search-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.search-row input, .search-row select { width: auto; min-width: 220px; }
.alert { margin: 14px 26px 0; padding: 12px 14px; border-radius: 8px; border: 1px solid var(--line); background: #fff; }
.alert.success { border-color: #abefc6; background: #ecfdf3; color: var(--ok); }
.alert.error { border-color: #fecdca; background: #fef3f2; color: var(--danger); }
.tabs { display: flex; gap: 8px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tabs a { padding: 9px 11px; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs a.active { color: var(--accent-dark); border-color: var(--accent); text-decoration: none; }
.login-body { display: grid; min-height: 100vh; place-items: center; padding: 20px; }
.login-card { width: min(420px, 100%); background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 24px; }
.login-brand { margin-bottom: 20px; }
.invoice-item-row { display: grid; grid-template-columns: 1fr 110px 140px 120px 40px; gap: 8px; align-items: end; margin-bottom: 8px; }
.right { text-align: right; }
.print-frame { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 18px; }
.code-area { min-height: 440px; font-family: Consolas, "Courier New", monospace; font-size: 13px; line-height: 1.5; }
.code-area.small-code { min-height: 150px; }
.mail-preview-frame { width: 100%; min-height: 620px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.logo-preview img { max-width: 220px; max-height: 100px; display: block; margin-top: 8px; border: 1px solid var(--line); border-radius: 6px; padding: 8px; background: #fff; }
.mail-list td:first-child { min-width: 220px; }
.mail-list td:nth-child(2) { min-width: 240px; }
.mail-unread td { font-weight: 700; background: #f6fffd; }
.mail-unread .badge, .mail-unread .muted { font-weight: 400; }
.mail-meta { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.mail-body { white-space: pre-wrap; overflow-x: auto; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 16px; font-family: Arial, Helvetica, sans-serif; line-height: 1.55; }
.mail-compose-body { min-height: 300px; }
.mail-html-preview { margin-top: 14px; }
.mail-html-preview summary { cursor: pointer; color: var(--accent-dark); font-weight: 700; margin-bottom: 10px; }
.mail-html-preview iframe { width: 100%; min-height: 520px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.mail-inline-check { width: auto; }
.mail-alert-inline { margin: 0 0 14px; }
@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.cols-2, .grid.cols-3, .grid.cols-4, .form-grid { grid-template-columns: 1fr; }
  .mail-meta { grid-template-columns: 1fr; }
  .invoice-item-row { grid-template-columns: 1fr 1fr; }
  .topbar { position: static; align-items: flex-start; gap: 12px; flex-direction: column; }
}
@media print {
  .sidebar, .topbar, .button, .toolbar, .nav, .alert { display: none !important; }
  .app-shell { display: block; }
  .content { padding: 0; }
  .panel, .print-frame { border: 0; padding: 0; }
}
