:root {
  --bg: #eef2f6;
  --surface: #ffffff;
  --surface-2: #f7fafc;
  --text: #17202a;
  --muted: #667085;
  --line: #d8e0e8;
  --primary: #176b87;
  --primary-dark: #0d4e66;
  --accent: #d78c38;
  --danger: #b42318;
  --success: #12805c;
  --warning: #b7791f;
  --shadow: 0 18px 50px rgba(23, 32, 42, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(23, 107, 135, 0.14), transparent 34%),
    linear-gradient(315deg, rgba(215, 140, 56, 0.12), transparent 30%),
    var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Arial, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 8px;
  background: var(--primary);
  color: white;
  cursor: pointer;
  font-weight: 700;
  min-height: 42px;
  padding: 0 18px;
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--text);
  outline: none;
  padding: 11px 12px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(23, 107, 135, 0.14);
}

label {
  color: var(--muted);
  display: grid;
  gap: 7px;
  font-size: 13px;
  font-weight: 700;
}

.hidden {
  display: none !important;
}

.login-view {
  align-items: center;
  display: flex;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.login-panel {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 12px;
  box-shadow: var(--shadow);
  max-width: 390px;
  padding: 34px;
  text-align: center;
  width: 100%;
}

.brand-mark {
  align-items: center;
  background: var(--primary);
  border-radius: 12px;
  color: white;
  display: inline-flex;
  font-size: 30px;
  font-weight: 900;
  height: 62px;
  justify-content: center;
  margin-bottom: 18px;
  width: 62px;
}

.login-panel h1,
.topbar h1,
.section-heading h2 {
  letter-spacing: 0;
  margin: 0;
}

.login-panel h1 {
  font-size: 34px;
}

.login-panel p {
  color: var(--muted);
  margin: 6px 0 22px;
}

.login-panel form {
  display: grid;
  gap: 12px;
}

.form-error {
  color: var(--danger);
  min-height: 22px;
  padding-top: 12px;
}

.app-view {
  margin: 0 auto;
  max-width: 1480px;
  padding: 22px;
}

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

.eyebrow {
  color: var(--primary);
  font-size: 13px;
  font-weight: 900;
  margin: 0 0 4px;
}

.topbar h1 {
  font-size: 30px;
}

.top-actions,
.dialog-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.ghost-btn,
.secondary-btn,
.text-btn {
  background: white;
  border: 1px solid var(--line);
  color: var(--text);
}

.ghost-btn:hover,
.secondary-btn:hover,
.text-btn:hover {
  background: var(--surface-2);
}

.secondary-btn {
  color: var(--primary);
}

.text-btn {
  border: 0;
  color: var(--primary);
  min-height: 34px;
  padding: 0 8px;
}

.danger-btn {
  background: #fff2f0;
  border: 1px solid #f3b8b0;
  color: var(--danger);
}

.danger-btn:hover {
  background: #ffe5e0;
}

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

.stats-grid article,
.reminder-panel,
.filter-bar,
.list-panel,
.form-panel,
dialog {
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(23, 32, 42, 0.08);
}

.stats-grid article {
  display: grid;
  gap: 3px;
  min-height: 58px;
  padding: 8px 12px;
}

.stats-grid span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.stats-grid strong {
  font-size: 22px;
  line-height: 1;
}

.reminder-panel {
  display: grid;
  gap: 10px;
  margin-bottom: 10px;
  padding: 12px;
}

.reminder-panel h2 {
  font-size: 18px;
  letter-spacing: 0;
  margin: 0 0 4px;
}

.reminder-panel p {
  color: var(--muted);
  font-size: 13px;
  margin: 0;
}

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

.reminder-card {
  align-items: start;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  display: grid;
  gap: 2px;
  justify-items: start;
  min-height: 62px;
  padding: 10px 12px;
  text-align: left;
}

.reminder-card:hover,
.reminder-card.active {
  background: #fff8ec;
  border-color: var(--accent);
  color: var(--text);
}

.reminder-card.active em {
  color: var(--danger);
}

.reminder-card span {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  font-weight: 800;
}

.reminder-card em {
  color: var(--primary-dark);
  font-size: 18px;
  font-style: normal;
  font-weight: 900;
  line-height: 1.1;
}

.active-filter-text {
  background: #fff8ec;
  border: 1px solid rgba(215, 140, 56, 0.38);
  border-radius: 8px;
  color: var(--warning) !important;
  display: none;
  font-size: 13px;
  font-weight: 800;
  padding: 8px 10px;
}

.active-filter-text:not(:empty) {
  display: block;
}

.filter-bar {
  align-items: end;
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(4, minmax(130px, 1fr)) auto auto auto;
  margin-bottom: 10px;
  padding: 8px;
}

.filter-bar label {
  gap: 4px;
}

.filter-bar input,
.filter-bar select {
  min-height: 34px;
  padding: 7px 10px;
}

.filter-bar button {
  min-height: 34px;
  padding: 0 12px;
}

.workspace {
  align-items: start;
  display: grid;
  gap: 14px;
  grid-template-columns: 390px minmax(0, 1fr);
}

.list-panel,
.form-panel {
  padding: 18px;
}

.form-panel {
  position: sticky;
  top: 14px;
}

.list-panel {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 230px);
  min-height: 420px;
}

.section-heading {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin-bottom: 14px;
}

.section-heading h2 {
  font-size: 20px;
}

.section-heading span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.document-list {
  display: grid;
  flex: 1;
  gap: 10px;
  min-height: 0;
  overflow: auto;
  padding-right: 4px;
}

.pagination {
  align-items: center;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 12px;
  padding-top: 12px;
}

.pagination span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.pagination button {
  min-height: 34px;
  padding: 0 12px;
}

.document-card {
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 14px;
  grid-template-columns: 1fr auto;
  padding: 14px;
}

.document-card:hover {
  border-color: rgba(23, 107, 135, 0.45);
}

.document-card.expired-card {
  background: #fff5f3;
  border: 2px solid var(--danger);
  box-shadow: 0 12px 34px rgba(180, 35, 24, 0.16);
}

.document-card.expired-card .document-title strong {
  color: var(--danger);
  font-size: 22px;
  text-transform: uppercase;
}

.document-card.soon-card {
  border-color: rgba(183, 121, 31, 0.55);
}

.document-main {
  min-width: 0;
}

.document-title {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.document-title strong {
  font-size: 17px;
}

.badge {
  border-radius: 999px;
  display: inline-flex;
  font-size: 12px;
  font-weight: 900;
  padding: 5px 9px;
}

.badge.ok {
  background: #e7f6ef;
  color: var(--success);
}

.badge.soon {
  background: #fff4de;
  color: var(--warning);
}

.badge.expired {
  background: #ffe8e5;
  color: var(--danger);
  font-size: 14px;
  padding: 7px 11px;
  text-transform: uppercase;
}

.meta {
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 13px;
}

.expired-detail {
  color: var(--danger);
  font-size: 15px;
  font-weight: 900;
}

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

.small-btn {
  min-height: 36px;
  padding: 0 12px;
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.document-form,
.settings-form {
  display: grid;
  gap: 13px;
}

.hint {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  margin: 14px 0 0;
}

dialog {
  border: 0;
  max-width: 820px;
  padding: 20px;
  width: calc(100% - 28px);
}

dialog::backdrop {
  background: rgba(23, 32, 42, 0.45);
}

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

.check-label {
  align-content: end;
  align-items: center;
  display: flex;
  flex-direction: row;
  gap: 10px;
  min-height: 66px;
}

.check-label input {
  width: auto;
}

.empty-state {
  align-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  display: grid;
  gap: 6px;
  justify-items: center;
  padding: 42px 18px;
  text-align: center;
}

.empty-state strong {
  color: var(--text);
}

@media (max-width: 1050px) {
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

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

  .form-panel {
    position: static;
  }

  .list-panel {
    max-height: none;
  }

}

@media (max-width: 650px) {
  .app-view {
    padding: 14px;
  }

  .topbar,
  .document-card {
    align-items: stretch;
    grid-template-columns: 1fr;
  }

  .topbar {
    flex-direction: column;
  }

  .stats-grid,
  .reminder-grid,
  .settings-grid {
    grid-template-columns: 1fr;
  }

  .top-actions,
  .dialog-actions,
  .card-actions {
    width: 100%;
  }

  .top-actions button,
  .dialog-actions button,
  .card-actions button {
    flex: 1;
  }
}

@media print {
  body {
    background: white;
  }

  .topbar,
  .stats-grid,
  .filter-bar,
  .form-panel,
  .card-actions,
  dialog {
    display: none !important;
  }

  .app-view {
    max-width: none;
    padding: 0;
  }

  .workspace {
    display: block;
  }

  .list-panel {
    border: 0;
    box-shadow: none;
  }

  .document-card {
    break-inside: avoid;
  }
}
