:root {
  --accent: #3755fa;
  --accent-hover: #2a42c7;
  --border: #e4e7ed;
  --text: #303133;
  --muted: #909399;
  --bg: #f5f7fa;
  --card: #fff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.topbar h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.topbar nav a {
  margin-right: 16px;
  font-weight: 500;
}

.topbar .user {
  color: var(--muted);
  font-size: 13px;
}

.wrap {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 20px;
}

.card h2 {
  margin: 0 0 16px;
  font-size: 16px;
  font-weight: 600;
}

label {
  display: block;
  margin-bottom: 6px;
  font-weight: 500;
  font-size: 13px;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
select {
  width: 100%;
  max-width: 360px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 14px;
}

.select2-container {
  width: 100% !important;
  max-width: 360px;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(55, 85, 250, 0.15);
}

input[type="date"] {
  appearance: none;
  -webkit-appearance: none;
  min-height: 36px;
  line-height: 1.2;
  background: #fff;
}

.btn {
  display: inline-block;
  padding: 8px 16px;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  background: var(--accent);
  color: #fff;
}

.btn:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--bg);
}

.btn-success {
  background: #67c23a;
  color: #fff;
}

.btn-success:hover {
  background: #5daf34;
}

.form-actions {
  margin-top: 16px;
}

.err {
  color: #f56c6c;
  font-size: 13px;
  margin-top: 8px;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table.data th,
table.data td {
  border: 1px solid var(--border);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}

table.data th {
  background: #fafafa;
  font-weight: 600;
}

table.data tr:nth-child(even) {
  background: #fafafa;
}

table.data tr.group-row td {
  background: #f0f4ff;
  font-weight: 600;
}

.pager {
  margin-top: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.kw-filters {
  margin-bottom: 12px;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: nowrap;
  overflow-x: auto;
}

.kw-date-group {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  margin-top: 24px;
}

.kw-date-group input[type="text"] {
  min-height: 36px;
  cursor: pointer;
  padding-right: 30px;
  background-color: #fff;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23909999' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4' width='18' height='18' rx='2' ry='2'/%3E%3Cline x1='16' y1='2' x2='16' y2='6'/%3E%3Cline x1='8' y1='2' x2='8' y2='6'/%3E%3Cline x1='3' y1='10' x2='21' y2='10'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

.kw-date-group input[type="text"]:hover {
  cursor: pointer;
}

.kw-filters-stack {
  margin-bottom: 12px;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-wrap: nowrap;
  overflow-x: auto;
}

.kw-search-block input[type="text"] {
  width: 400px;
  max-width: 400px;
}

.kw-range-stack {
  display: flex;
  flex-direction: row;
  gap: 10px;
  margin-top: 0;
}

.kw-date-field label {
  margin-bottom: 6px;
}

.kw-date-field input[type="text"] {
  width: 160px;
  max-width: 160px;
  min-height: 36px;
  cursor: pointer;
  padding-right: 30px;
  background-color: #fff;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23909999' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4' width='18' height='18' rx='2' ry='2'/%3E%3Cline x1='16' y1='2' x2='16' y2='6'/%3E%3Cline x1='8' y1='2' x2='8' y2='6'/%3E%3Cline x1='3' y1='10' x2='21' y2='10'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

.kw-actions-apply,
.kw-actions-range,
.kw-actions-export {
  margin-top: 0;
}

.kw-actions-apply .btn,
.kw-actions-export .btn {
  width: auto;
}

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

.kw-actions-range .btn {
  flex: 0 0 auto;
}

.kw-actions {
  display: flex;
  gap: 8px;
  flex-wrap: nowrap;
  white-space: nowrap;
  margin-top: 23px;
  flex-shrink: 0;
  align-items: center;
}

#hist-table th.sortable {
  white-space: nowrap;
}

#hist-table th.sortable .th-arrow {
  display: inline-block;
  width: 1em;
  margin-left: 4px;
  text-align: center;
}

#hist-table th.sortable.is-asc .th-arrow::before {
  content: "▲";
}

#hist-table th.sortable.is-desc .th-arrow::before {
  content: "▼";
}

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

.login-box {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 32px;
}

.login-box h1 {
  margin: 0 0 24px;
  font-size: 20px;
}

.login-box .field {
  margin-bottom: 16px;
}

@media (max-width: 1349px) {
  .kw-filters-stack {
    flex-wrap: wrap;
    overflow-x: visible;
  }
}

/* Tablet */
@media (max-width: 1024px) {
  .wrap {
    padding: 16px;
  }

  .card {
    padding: 16px;
  }

  .topbar {
    padding: 10px 16px;
    gap: 10px;
  }

  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="date"],
  select {
    max-width: 100%;
  }

  table.data th,
  table.data td {
    padding: 7px 8px;
  }
}

/* Mobile */
@media (max-width: 768px) {
  body {
    font-size: 13px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar nav {
    width: 100%;
  }

  .topbar nav a {
    margin-right: 12px;
  }

  .topbar > div:last-child {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .wrap {
    padding: 12px;
  }

  .card {
    padding: 12px;
    margin-bottom: 12px;
  }

  .kw-filters {
    gap: 6px;
  }

  .kw-filters-stack {
    display: block;
    overflow-x: visible;
  }

  .kw-search-block input[type="text"] {
    width: 100%;
    max-width: 100%;
  }

  .kw-range-stack {
    flex-direction: column;
    margin-top: 8px;
  }

  .kw-date-field input[type="text"] {
    width: 100%;
    max-width: 100%;
  }

  .kw-actions {
    margin-top: 10px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: 100%;
    white-space: normal;
  }

  .kw-actions .btn {
    width: 100%;
  }

  .btn {
    padding: 8px 12px;
    font-size: 13px;
  }

  table.data {
    font-size: 12px;
  }

  table.data th,
  table.data td {
    padding: 6px 7px;
    white-space: nowrap;
  }

  .login-page {
    padding: 12px;
  }

  .login-box {
    max-width: 100%;
    padding: 20px 16px;
  }
}

/* Large desktop */
@media (min-width: 1440px) {
  .wrap {
    max-width: 1400px;
  }
}
