:root {
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-muted: #eef3f2;
  --text: #17211f;
  --muted: #66736f;
  --line: #d9e1df;
  --primary: #0f766e;
  --primary-strong: #115e59;
  --accent: #b45309;
  --danger: #b91c1c;
  --shadow: 0 10px 28px rgba(23, 33, 31, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

a {
  color: var(--primary-strong);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 18px;
  min-height: 64px;
  padding: 10px clamp(16px, 4vw, 40px);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-weight: 700;
  min-width: max-content;
}

.brand:hover {
  text-decoration: none;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius);
  background: var(--primary);
  color: white;
  font-weight: 800;
  font-size: 13px;
}

.main-nav {
  display: flex;
  flex: 1;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.main-nav a,
.nav-back {
  padding: 8px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.main-nav a:hover,
.nav-back:hover {
  background: var(--surface-muted);
  color: var(--text);
  text-decoration: none;
}

.logout-form {
  margin-left: auto;
}

.page {
  width: min(1180px, calc(100% - 32px));
  margin: 28px auto 56px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}

h1,
h2 {
  margin: 0;
  line-height: 1.1;
}

h1 {
  font-size: 30px;
}

h2 {
  font-size: 18px;
}

.page-header p,
.panel-heading p {
  margin: 6px 0 0;
  color: var(--muted);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 9px 14px;
  border: 1px solid transparent;
  border-radius: 7px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.button:hover {
  text-decoration: none;
}

.button-primary {
  background: var(--primary);
  color: white;
}

.button-primary:hover {
  background: var(--primary-strong);
}

.button-secondary {
  background: var(--surface);
  border-color: var(--line);
  color: var(--text);
}

.button-secondary:hover {
  border-color: var(--primary);
}

.button-ghost {
  background: transparent;
  color: var(--muted);
}

.button-ghost:hover {
  background: var(--surface-muted);
  color: var(--text);
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel-heading,
.detail-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 18px 0;
}

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

.stat-card {
  min-height: 112px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.stat-card span {
  display: block;
  color: var(--muted);
  font-weight: 700;
}

.stat-card strong {
  display: block;
  margin-top: 10px;
  font-size: 34px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

th,
td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

tr:last-child td {
  border-bottom: 0;
}

.empty {
  color: var(--muted);
  text-align: center;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
}

.status-new,
.status-planned {
  color: #164e63;
  background: #dff6fb;
}

.status-in_progress {
  color: #7c2d12;
  background: #ffedd5;
}

.status-done {
  color: #14532d;
  background: #dcfce7;
}

.status-cancelled,
.priority-urgent {
  color: #7f1d1d;
  background: #fee2e2;
}

.priority-high {
  color: #7c2d12;
  background: #fed7aa;
}

.priority-normal {
  color: #115e59;
  background: #ccfbf1;
}

.priority-low {
  color: #475569;
  background: #e2e8f0;
}

.search-bar,
.filter-grid,
.form-grid {
  display: grid;
  gap: 14px;
}

.search-bar {
  grid-template-columns: minmax(0, 1fr) auto;
  margin-bottom: 18px;
}

.filter-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
  align-items: end;
  padding: 18px;
  margin-bottom: 18px;
}

.filter-actions {
  display: flex;
  gap: 8px;
}

.form-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding: 20px;
}

.field {
  display: grid;
  gap: 7px;
}

.field-wide {
  grid-column: 1 / -1;
}

label {
  color: var(--muted);
  font-weight: 700;
}

.input,
.select,
.textarea,
input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
  color: var(--text);
  font: inherit;
}

textarea,
.textarea {
  min-height: 112px;
  resize: vertical;
}

.input:focus,
.select:focus,
.textarea:focus,
input:focus,
select:focus,
textarea:focus {
  outline: 3px solid rgba(15, 118, 110, 0.16);
  border-color: var(--primary);
}

.form-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
}

.duration-fields {
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.duration-fields legend {
  padding: 0 6px;
  color: var(--muted);
  font-weight: 700;
}

.duration-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.form-errors,
.errorlist {
  margin: 0;
  padding: 10px 12px;
  border-radius: 7px;
  background: #fee2e2;
  color: var(--danger);
  list-style: none;
}

.messages {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
}

.message {
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
}

.message.success {
  border-color: #86efac;
  background: #dcfce7;
}

.login-shell {
  display: grid;
  place-items: center;
  min-height: calc(100vh - 150px);
}

.login-panel {
  width: min(420px, 100%);
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.login-heading {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}

.form-stack {
  display: grid;
  gap: 16px;
}

.muted-text {
  color: var(--muted);
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 10px;
}

.checkbox-field input[type="checkbox"] {
  width: 18px;
  min-height: 18px;
}

.security-panel {
  display: grid;
  gap: 14px;
  margin-top: 18px;
  padding: 20px;
}

.totp-qr {
  width: 180px;
  height: 180px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.detail-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.detail-layout .panel {
  padding: 18px;
}

.detail-full {
  grid-column: 1 / -1;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin: 16px 0 0;
}

.detail-grid div {
  min-width: 0;
}

dt {
  color: var(--muted);
  font-weight: 700;
}

dd {
  margin: 4px 0 0;
  overflow-wrap: anywhere;
}

.preline {
  white-space: pre-line;
  margin: 14px 0 0;
}

.print-body {
  background: #e9eef0;
}

.print-page {
  display: flex;
  flex-direction: column;
  width: min(210mm, calc(100% - 24px));
  height: 297mm;
  margin: 16px auto;
  padding: 10mm;
  background: white;
  color: #111827;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.print-header {
  display: grid;
  grid-template-columns: 1.05fr 0.8fr 1.05fr;
  align-items: stretch;
  gap: 10px;
  padding-bottom: 10px;
  border-bottom: 2px solid #0b4f7c;
}

.company-card {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 8px;
  min-width: 0;
}

.company-logo {
  width: 112px;
  max-height: 68px;
  object-fit: contain;
  object-position: left top;
}

.company-info {
  display: grid;
  align-content: start;
  gap: 2px;
  min-width: 0;
  font-size: 9.5px;
  line-height: 1.18;
}

.company-info strong {
  color: #0b4f7c;
  font-size: 11px;
  line-height: 1.2;
}

.company-info span {
  overflow-wrap: anywhere;
}

.print-title {
  display: grid;
  align-content: center;
  justify-items: center;
  padding: 10px 8px;
  border: 1px solid #0b4f7c;
  border-radius: 4px;
  text-align: center;
}

.print-title span {
  color: #0b4f7c;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.print-title strong {
  display: block;
  margin-top: 7px;
  font-size: 20px;
  line-height: 1.1;
}

.print-client-card {
  display: grid;
  align-content: start;
  gap: 4px;
  padding: 9px;
  border: 1px solid #9ca3af;
  border-radius: 4px;
}

.print-client-card h2 {
  margin: 0 0 3px;
  color: #0b4f7c;
  font-size: 11px;
  text-transform: uppercase;
}

.print-client-card strong {
  font-size: 12px;
  line-height: 1.2;
}

.print-client-card span {
  font-size: 10px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.print-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.print-grid-main {
  grid-template-columns: 1fr 1fr 0.85fr;
}

.print-text-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 10px;
}

.print-grid article,
.print-block,
.signature-area > div {
  border: 1px solid #9ca3af;
  border-radius: 4px;
  padding: 9px;
}

.print-grid h2,
.print-block h2,
.signature-area h2 {
  margin: 0 0 8px;
  color: #0b4f7c;
  font-size: 11px;
  text-transform: uppercase;
}

.print-grid dl {
  display: grid;
  gap: 5px;
  margin: 0;
}

.print-grid dt {
  color: #4b5563;
  font-size: 9px;
  font-weight: 800;
  text-transform: uppercase;
}

.print-grid dd {
  margin-top: 0;
  font-size: 11px;
  line-height: 1.25;
}

.print-block {
  margin-top: 0;
}

.print-block p {
  min-height: 58px;
  margin: 0;
  font-size: 11px;
  line-height: 1.35;
  white-space: pre-line;
}

.print-block-compact p {
  max-height: 118px;
  overflow: hidden;
}

.signature-area {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: auto;
  padding-top: 12px;
  break-inside: avoid;
}

.signature-area > div {
  min-height: 78px;
}

.signature-area p {
  margin: 0;
  color: #4b5563;
  font-size: 11px;
}

.print-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

@media (max-width: 860px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .logout-form {
    margin-left: 0;
  }

  .page-header {
    align-items: stretch;
    flex-direction: column;
  }

  .stats-grid,
  .detail-layout {
    grid-template-columns: 1fr;
  }

  .detail-full {
    grid-column: auto;
  }

  .filter-grid,
  .form-grid,
  .search-bar {
    grid-template-columns: 1fr;
  }

  .filter-actions,
  .form-actions {
    justify-content: stretch;
  }

  .filter-actions .button,
  .form-actions .button,
  .page-header .button {
    width: 100%;
  }

  .button-row {
    justify-content: stretch;
  }

  .button-row .button {
    flex: 1 1 100%;
  }

  .print-grid,
  .print-grid-main,
  .print-text-grid,
  .signature-area {
    grid-template-columns: 1fr;
  }

  .duration-grid {
    grid-template-columns: 1fr;
  }

  .print-header,
  .company-card {
    grid-template-columns: 1fr;
  }

  .print-header {
    display: grid;
  }

  .company-logo {
    width: min(260px, 100%);
  }

  .print-title {
    justify-items: start;
    text-align: left;
  }
}

@media (max-width: 560px) {
  .page {
    width: min(100% - 20px, 1180px);
    margin-top: 18px;
  }

  .brand {
    white-space: normal;
  }

  .main-nav {
    width: 100%;
  }

  .main-nav a {
    flex: 1 1 calc(50% - 8px);
    text-align: center;
    background: var(--surface-muted);
  }

  .nav-back {
    flex: 1 1 calc(50% - 8px);
    background: var(--surface-muted);
  }

  h1 {
    font-size: 25px;
  }

  .detail-grid {
    grid-template-columns: 1fr;
  }
}

@media print {
  @page {
    size: A4;
    margin: 5mm;
  }

  html,
  body,
  .print-body {
    background: white;
    margin: 0;
    width: 200mm;
  }

  .print-page {
    width: 200mm;
    height: 287mm;
    max-height: 287mm;
    margin: 0;
    padding: 10mm;
    box-shadow: none;
    overflow: hidden;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  .print-header {
    display: grid;
    grid-template-columns: 1.05fr 0.8fr 1.05fr;
    align-items: stretch;
    gap: 10px;
  }

  .company-card {
    grid-template-columns: 112px minmax(0, 1fr);
  }

  .company-logo {
    width: 112px;
  }

  .print-title {
    justify-items: center;
    text-align: center;
  }

  .print-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .print-grid-main {
    grid-template-columns: 1fr 1fr 0.85fr;
  }

  .print-text-grid,
  .signature-area {
    grid-template-columns: 1fr;
  }

  .print-actions {
    display: none !important;
  }
}
