:root {
  --navy: #0e2b45;
  --navy-2: #123a5c;
  --green: #0f8b4c;
  --green-soft: #dff4e8;
  --red: #d93025;
  --red-soft: #fde8e7;
  --yellow: #f59e0b;
  --yellow-soft: #fff3d7;
  --line: #dfe7ef;
  --text: #102033;
  --muted: #66788f;
  --bg: #f5f8fb;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--text);
  background: var(--bg);
}

a { color: inherit; text-decoration: none; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 260px;
  background: linear-gradient(180deg, var(--navy), #0a2035);
  color: #fff;
  padding: 22px 14px;
  transition: transform .2s ease;
}

.sidebar-toggle {
  position: absolute;
  top: 18px;
  right: -17px;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid rgba(255,255,255,.35);
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  cursor: pointer;
  font-size: 26px;
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 8px 18px rgba(16,32,51,.2);
  z-index: 10;
}

.sidebar-brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 0 10px 22px;
  border-bottom: 1px solid rgba(255,255,255,.14);
}

.brand-icon, .brand-mark {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 2px solid rgba(255,255,255,.75);
  border-radius: 8px;
  font-weight: 700;
}

.sidebar nav {
  display: grid;
  gap: 6px;
  margin-top: 18px;
}

.sidebar a {
  padding: 13px 14px;
  border-radius: 8px;
  color: rgba(255,255,255,.88);
}

.sidebar a.active, .sidebar a:hover {
  background: var(--green);
  color: #fff;
}

.app-shell {
  margin-left: 260px;
  min-height: 100vh;
  padding: 24px;
  transition: margin-left .2s ease;
}

body.sidebar-collapsed .sidebar {
  transform: translateX(-260px);
}

body.sidebar-collapsed .sidebar-toggle {
  right: -44px;
}

body.sidebar-collapsed .app-shell,
body.sidebar-collapsed .admin-content {
  margin-left: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}

.topbar h1 { margin: 0 0 6px; font-size: 30px; }
.topbar p, .muted { margin: 0; color: var(--muted); }

.user-chip {
  display: grid;
  gap: 3px;
  text-align: right;
}

.toolbar, .table-tools {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.toolbar {
  margin: 22px 0;
  align-items: flex-end;
}

.date-control {
  display: grid;
  gap: 8px;
}

.date-control label {
  display: block;
  font-weight: 700;
}

.date-control input {
  width: 170px;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 40px;
}

.toolbar-actions .muted {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  white-space: nowrap;
}

input, select, textarea {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  font: inherit;
  background: #fff;
}

label {
  display: grid;
  gap: 7px;
  font-weight: 600;
}

.btn {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 15px;
  background: #fff;
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
}

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

.btn-small { min-height: 32px; padding: 6px 10px; color: var(--green); }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}

.stat-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 8px 24px rgba(16,32,51,.05);
}

.stat-card span {
  display: block;
  color: var(--muted);
  margin-bottom: 12px;
}

.stat-card strong { font-size: 32px; }
.stat-card.success strong { color: var(--green); }
.stat-card.warning strong { color: var(--yellow); }
.stat-card.danger strong { color: var(--red); }

.table-panel, .admin-panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.table-tools {
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.table-wrap { overflow: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

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

th {
  background: #f8fafc;
  color: #2f4054;
  font-size: 13px;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border-radius: 7px;
  padding: 5px 10px;
  font-size: 13px;
  font-weight: 700;
}

.status.success { color: var(--green); background: var(--green-soft); }
.status.warning { color: #b86400; background: var(--yellow-soft); }
.status.danger { color: var(--red); background: var(--red-soft); }
.status.neutral { color: #344255; background: #edf2f7; }

.message-preview {
  max-width: 260px;
  line-height: 1.35;
}

.message-preview span {
  font-weight: 600;
}

.message-full {
  margin-top: 8px;
  max-height: 260px;
  overflow: auto;
  white-space: pre-wrap;
  color: var(--muted);
  font-size: 13px;
}

.link-button {
  display: inline;
  border: 0;
  background: transparent;
  color: var(--green);
  padding: 0 0 0 6px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--navy), var(--navy-2));
}

.login-card {
  width: min(420px, calc(100vw - 32px));
  background: #fff;
  border-radius: 10px;
  padding: 32px;
  box-shadow: 0 24px 70px rgba(0,0,0,.28);
}

.login-card .brand-mark {
  color: var(--navy);
  border-color: var(--navy);
}

.login-card h1 { margin: 18px 0 8px; }
.login-card p { color: var(--muted); margin: 0 0 22px; }
.login-card form { display: grid; gap: 16px; }

.alert {
  padding: 12px 14px;
  border-radius: 8px;
  margin-bottom: 16px;
}

.alert-danger { background: var(--red-soft); color: var(--red); }
.alert-success { background: var(--green-soft); color: var(--green); }

.admin-content {
  margin-left: 260px;
  padding: 24px;
  transition: margin-left .2s ease;
}

.form-grid {
  display: grid;
  gap: 14px;
  max-width: 760px;
  padding: 20px;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.calendar-refresh-form {
  padding: 0 20px 20px;
}

@media (max-width: 1100px) {
  .stat-grid { grid-template-columns: repeat(2, minmax(150px, 1fr)); }
}

@media (max-width: 760px) {
  body {
    background: #f7fafc;
    padding-bottom: 78px;
  }

  .sidebar {
    position: sticky;
    top: 0;
    width: 100%;
    transform: none !important;
    z-index: 30;
    padding: 12px 16px 14px;
    border-radius: 0 0 20px 20px;
    box-shadow: 0 12px 32px rgba(6, 22, 38, .22);
  }

  .sidebar-toggle { display: none; }

  .sidebar-brand {
    display: grid;
    grid-template-columns: 50px 1fr;
    grid-template-areas:
      "icon name"
      "icon title";
    column-gap: 12px;
    align-items: center;
    border-bottom: 0;
    padding: 0;
  }

  .sidebar-brand::after {
    content: "Дашборд";
    grid-area: title;
    display: block;
    margin-top: 2px;
    font-size: 22px;
    font-weight: 700;
  }

  .sidebar-brand strong {
    grid-area: name;
    font-size: 16px;
    line-height: 1.15;
  }

  .brand-icon {
    grid-area: icon;
    width: 50px;
    height: 50px;
    flex: 0 0 auto;
  }

  .sidebar nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(92px, 112px);
    justify-content: start;
    gap: 6px;
    margin: 0;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    overflow-x: auto;
    overscroll-behavior-x: contain;
    background: linear-gradient(180deg, var(--navy), #071c30);
    box-shadow: 0 -10px 28px rgba(6, 22, 38, .22);
    z-index: 40;
    scrollbar-width: none;
  }

  .sidebar nav::-webkit-scrollbar {
    display: none;
  }

  .sidebar a {
    display: grid;
    place-items: center;
    min-height: 52px;
    padding: 8px 7px;
    border: 1px solid rgba(255,255,255,.22);
    border-radius: 8px;
    background: rgba(255,255,255,.04);
    color: rgba(255,255,255,.9);
    font-size: 11px;
    font-weight: 700;
    line-height: 1.15;
    text-align: center;
    white-space: normal;
    overflow-wrap: normal;
    word-break: normal;
  }

  .sidebar a.active, .sidebar a:hover {
    border-color: var(--green);
    background: var(--green);
    color: #fff;
  }

  .app-shell, .admin-content {
    margin-left: 0;
    padding: 10px;
  }

  .topbar {
    display: none;
  }

  .toolbar {
    display: grid;
    grid-template-columns: 1fr;
    align-items: stretch;
    gap: 10px;
    margin: 0 0 10px;
    padding: 12px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: 0 8px 22px rgba(16,32,51,.06);
  }

  .date-control {
    gap: 7px;
  }

  .date-control input {
    width: 100%;
    min-height: 44px;
    font-size: 16px;
  }

  .toolbar-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    min-height: 0;
  }

  .toolbar-actions .btn {
    min-height: 44px;
    padding: 10px 12px;
  }

  .toolbar-actions .muted {
    grid-column: 1 / -1;
    min-height: auto;
    font-size: 13px;
  }

  .stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 10px;
  }

  .stat-card {
    padding: 11px 12px;
    min-height: 76px;
  }

  .stat-card span {
    margin-bottom: 5px;
    font-size: 13px;
  }

  .stat-card strong {
    font-size: 26px;
  }

  .table-panel {
    border-radius: 12px;
  }

  .table-tools {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    padding: 10px;
  }

  .table-tools select {
    display: none;
  }

  .table-tools input {
    min-width: 0;
    min-height: 42px;
  }

  .table-tools .btn {
    min-height: 42px;
    white-space: nowrap;
  }

  .table-wrap {
    overflow: visible;
  }

  #reportsTable,
  #reportsTable tbody,
  #reportsTable tr,
  #reportsTable td {
    display: block;
  }

  #reportsTable thead {
    display: none;
  }

  #reportsTable tr {
    position: relative;
    display: grid;
    grid-template-columns: 42px 1fr auto;
    grid-template-areas:
      "idx report status"
      "idx code deadline";
    gap: 4px 10px;
    align-items: center;
    min-height: 66px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    background: #fff;
  }

  #reportsTable td {
    border: 0;
    padding: 0;
  }

  #reportsTable .col-index {
    grid-area: idx;
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--navy);
    color: #fff;
    font-weight: 700;
  }

  #reportsTable .col-report {
    grid-area: report;
    min-width: 0;
    font-weight: 700;
    font-size: 14px;
    line-height: 1.2;
  }

  #reportsTable .col-code {
    grid-area: code;
    color: var(--muted);
    font-size: 13px;
  }

  #reportsTable .col-deadline {
    grid-area: deadline;
    justify-self: end;
    color: #27364a;
    font-size: 14px;
    white-space: nowrap;
  }

  #reportsTable .col-deadline::before {
    content: "◷ ";
    color: var(--muted);
  }

  #reportsTable .col-status {
    grid-area: status;
    justify-self: end;
  }

  #reportsTable .status {
    min-height: 26px;
    padding: 5px 9px;
    font-size: 12px;
    white-space: nowrap;
  }

  #reportsTable .col-file,
  #reportsTable .col-report-date,
  #reportsTable .col-department,
  #reportsTable .col-upload-date,
  #reportsTable .col-message {
    display: none;
  }
}
