:root {
  --bg: #eef2f6;
  --panel: #ffffff;
  --line: #cad4de;
  --line-dark: #9aa8b6;
  --text: #102235;
  --muted: #5c6e81;
  --primary: #1a56d2;
  --danger: #c33a45;
  --weekend: #f7f9fb;
  --shadow: 0 10px 28px rgba(16, 34, 53, 0.08);
  --radius: 18px;
  --sheet-scale: 1;
  --font-scale: 1;
  --computed-row-height: 21.2px;
  --computed-sign-height: 12.5px;
  --computed-line-height: 10.2px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; min-height: 100%; }
body {
  font-family: Arial, Helvetica, sans-serif;
  color: var(--text);
  background: var(--bg);
  overflow-x: hidden;
}

input, select, button { font: inherit; }
input[type="range"] { width: 100%; accent-color: var(--primary); }
.wrap { width: min(1220px, calc(100% - 24px)); margin: 0 auto; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(238, 242, 246, 0.96);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid #dce4eb;
}

.header-inner {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 16px 0;
}

.brand {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--primary);
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 4px; font-size: clamp(22px, 2.7vw, 32px); }
h2 { margin-bottom: 0; font-size: 18px; }
.subtext { margin-bottom: 0; color: var(--muted); }

.header-actions, .controls-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.layout { padding: 20px 0 40px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 18px;
}

.controls-panel { position: sticky; top: 84px; z-index: 20; }
.section-head { margin-bottom: 12px; }
.section-head-tight { margin-top: 16px; }

.controls-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.controls-grid-advanced .field {
  padding: 12px;
  border: 1px solid #dde5ec;
  border-radius: 14px;
  background: #fbfcfe;
}

.field { display: flex; flex-direction: column; gap: 8px; }
.field-wide { grid-column: span 2; }
.field span { font-size: 13px; font-weight: 700; color: var(--muted); }
.field strong { color: var(--text); }

input[type="text"], select, input[type="file"] {
  min-height: 44px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: #fff;
  color: var(--text);
}

input[type="file"] { padding: 9px 12px; }
input:focus, select:focus {
  outline: 2px solid rgba(26, 86, 210, 0.14);
  border-color: var(--primary);
}

.btn {
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  font-weight: 700;
  padding: 0 16px;
  cursor: pointer;
}

.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-danger { color: var(--danger); }

.paper {
  background: #fff;
  border: 1px solid #d5dee6;
  border-radius: 22px;
  box-shadow: 0 18px 42px rgba(16, 34, 53, 0.12);
  overflow: hidden;
}

.paper-inner {
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  aspect-ratio: 1 / 1.414;
  padding: 10px 12px 8px;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  transform: scale(var(--sheet-scale));
  transform-origin: top center;
}

.sheet-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
  margin-bottom: 6px;
}

.sheet-branding {
  display: flex;
  gap: 10px;
  align-items: center;
  min-width: 0;
}

.logo-slot {
  width: 72px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #fafcfe 0%, #f4f7fa 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex: 0 0 72px;
}

.logo-slot img { width: 100%; height: 100%; object-fit: contain; }

.company-title {
  border: none;
  background: transparent;
  padding: 0;
  font-size: clamp(15px, 1.6vw, 23px);
  font-weight: 800;
  line-height: 1.02;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text);
  width: min(100%, 300px);
}
.company-title:focus { outline: none; }

.sheet-caption {
  margin: 2px 0 0;
  font-size: calc(9px * var(--font-scale));
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.sheet-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(112px, 1fr));
  gap: 6px;
  flex: 0 0 252px;
}

.meta-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 9px;
  background: #fbfcfd;
  min-height: 48px;
}
.meta-card span {
  display: block;
  font-size: calc(9px * var(--font-scale));
  color: var(--muted);
  margin-bottom: 4px;
}
.meta-card strong {
  display: block;
  min-height: 16px;
  font-size: calc(11px * var(--font-scale));
}

.table-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  flex: 1 1 auto;
  min-height: 0;
}

table {
  width: 100%;
  height: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

thead th {
  background: #eef3f8;
  border-bottom: 1px solid var(--line);
  padding: 4px 4px;
  text-align: left;
  font-size: calc(8.9px * var(--font-scale));
  line-height: 1.05;
  white-space: nowrap;
}

tbody td {
  border-bottom: 1px solid #e3e9ef;
  padding: 2px 4px;
  height: var(--computed-row-height);
  font-size: calc(8.8px * var(--font-scale));
  line-height: 1;
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
.col-date { width: 11%; }
.col-day { width: 8%; }
.col-sign { width: 12.5%; }
.weekend-row { background: var(--weekend); }
.weekend-mark::after {
  content: "Wknd";
  display: inline-block;
  margin-left: 4px;
  padding: 1px 4px;
  border: 1px solid #ced7df;
  border-radius: 999px;
  font-size: calc(7.8px * var(--font-scale));
  color: var(--muted);
}

.blank-line {
  display: block;
  width: 100%;
  height: var(--computed-line-height);
  border-bottom: 1px solid var(--line-dark);
}

.sign-box {
  display: block;
  width: 100%;
  height: var(--computed-sign-height);
  border: 1px solid #b9c4ce;
  border-radius: 4px;
  background: #fff;
}

.monthly-total {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
  font-size: calc(11.5px * var(--font-scale));
  font-weight: 700;
  flex: 0 0 auto;
}

.monthly-total-box {
  display: inline-block;
  width: 72px;
  height: 22px;
  border: 1px solid #b9c4ce;
  border-radius: 5px;
  background: #fff;
}

@media (max-width: 980px) {
  .controls-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sheet-head { flex-direction: column; }
  .sheet-meta { width: 100%; flex: auto; }
  .paper-inner { aspect-ratio: auto; padding: 14px; transform: none; }
  .table-wrap { overflow: auto; height: auto !important; }
  table { min-width: 860px; height: auto; }
}

@media (max-width: 640px) {
  .header-inner { flex-direction: column; align-items: stretch; }
  .controls-grid { grid-template-columns: 1fr; }
  .field-wide { grid-column: span 1; }
  .header-actions, .controls-actions { justify-content: stretch; }
  .btn { flex: 1 1 auto; }
  .sheet-branding { align-items: flex-start; }
  .sheet-meta { grid-template-columns: 1fr; }
}

@page {
  size: A4 portrait;
  margin: 5mm;
}

@media print {
  html, body {
    width: 210mm;
    height: 297mm;
    overflow: hidden;
  }

  body {
    background: #fff;
    color: #000;
  }

  .no-print,
  .app-header,
  .controls-panel {
    display: none !important;
  }

  .wrap {
    width: 100%;
    margin: 0;
  }

  .layout { padding: 0; }

  .paper {
    border: none;
    box-shadow: none;
    border-radius: 0;
    overflow: visible;
  }

  .paper-inner {
    width: 100%;
    max-width: none;
    aspect-ratio: auto;
    min-height: 286mm;
    height: 286mm;
    padding: 0;
    margin: 0;
    transform: scale(1);
  }

  .sheet-head { gap: 8px; margin-bottom: 6px; }
  .logo-slot { width: 78px; height: 42px; flex-basis: 78px; }
  .company-title { pointer-events: none; font-size: 20px; }
  .sheet-caption { font-size: calc(9px * var(--font-scale)); }
  .meta-card { min-height: 50px; }

  .table-wrap {
    border-radius: 0;
    page-break-inside: avoid;
    overflow: hidden;
  }

  table {
    min-width: 0;
    width: 100%;
    height: 100%;
  }

  thead th {
    font-size: calc(8.7px * var(--font-scale));
    padding: 4px 4px;
  }

  tbody td {
    height: var(--computed-row-height);
    padding: 2px 4px;
    font-size: calc(8.6px * var(--font-scale));
  }

  .blank-line { height: var(--computed-line-height); }
  .sign-box { height: var(--computed-sign-height); }
  .monthly-total { margin-top: 5px; font-size: calc(11px * var(--font-scale)); }
  .monthly-total-box { width: 72px; height: 22px; }
}
