:root {
  --bg: #eff2f8;
  --surface: #ffffff;
  --surface-soft: #f6f7fd;
  --text: #202744;
  --muted: #8490b2;
  --line: #e3e7f2;
  --primary: #5b6cff;
  --primary-strong: #4656e8;
  --accent: #ff2f7d;
  --purple: #9b18f0;
  --cyan: #20c4b2;
  --danger: #dc2626;
  --success: #20c4b2;
  --warning: #cbd3e3;
  --sidebar: #202638;
  --sidebar-deep: #1a2030;
  --shadow: 0 16px 34px rgba(37, 47, 85, .10);
}

* { box-sizing: border-box; }

body {
  font-family: Arial, Helvetica, sans-serif !important;
  background: var(--bg) !important;
  color: var(--text);
  padding: 28px 24px 46px 284px !important;
  transition: padding-left .2s ease;
}

body.sidebar-collapsed {
  padding-left: 102px !important;
}

body.public-home {
  padding: 24px !important;
}

h2 {
  color: var(--text);
  letter-spacing: 0;
  font-size: 22px;
  margin-bottom: 16px;
}
h3 { color: var(--text); letter-spacing: 0; }

.card, .box {
  background: var(--surface) !important;
  border: 1px solid var(--line);
  border-radius: 8px !important;
  box-shadow: var(--shadow) !important;
}

table { color: var(--text); }
th {
  background: var(--surface-soft) !important;
  color: #3b4568;
  font-weight: 700;
}
td, th { border-bottom-color: var(--line) !important; }

input, select, textarea {
  background: #fff;
  border: 1px solid #d6dceb !important;
  border-radius: 6px !important;
  color: var(--text);
  min-height: 36px;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}

input:focus, select:focus, textarea:focus,
.search-select.is-open .search-select__button {
  border-color: var(--primary) !important;
  box-shadow: 0 0 0 3px rgba(91, 108, 255, .16);
}

input[type="date"], input[type="time"], input[type="month"], input[type="number"] {
  color-scheme: light;
}

button, .btn {
  border-radius: 6px !important;
  background: var(--primary) !important;
  color: #fff !important;
  font-weight: 700;
  border: 0 !important;
}

button:hover, .btn:hover { background: var(--primary-strong) !important; }
button:disabled,
button.is-loading {
  opacity: .72;
  cursor: wait !important;
}
.btn-export { background: var(--success) !important; }
.btn-edit { background: var(--cyan) !important; }
.btn-del { background: var(--danger) !important; }

.msg, .ok, .err { border-radius: 6px !important; }
.ok { background: #dcfce7 !important; color: #166534 !important; }
.err { background: #fee2e2 !important; color: #991b1b !important; }

.nav {
  background: linear-gradient(180deg, var(--sidebar), var(--sidebar-deep)) !important;
  border-right: 1px solid rgba(255,255,255,.06);
  box-shadow: 18px 0 38px rgba(21, 27, 44, .20);
  transition: width .2s ease, padding .2s ease;
}
.nav a {
  border-radius: 6px !important;
  box-sizing: border-box;
  flex-shrink: 0;
  transform: none !important;
}
.nav a.active, .nav a:hover { background: rgba(91, 108, 255, .18) !important; }
.nav a:focus { outline: none; box-shadow: 0 0 0 3px rgba(91, 108, 255, .22); }
.nav .user { color: #aeb9d4 !important; }

.sidebar-toggle {
  width: 42px;
  height: 38px;
  min-height: 38px;
  margin: 0 !important;
  padding: 0 !important;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  background: rgba(255,255,255,.06) !important;
  border: 1px solid rgba(255,255,255,.08) !important;
  box-shadow: none;
  flex-shrink: 0;
  transform: none !important;
}

.sidebar-toggle span {
  display: block;
  width: 18px;
  height: 2px;
  border-radius: 2px;
  background: #fff;
}

body.sidebar-collapsed .nav {
  width: 78px;
  padding: 20px 12px;
  align-items: center;
  gap: 8px;
}

body.sidebar-collapsed .nav .brand {
  width: 42px;
  min-width: 42px;
  height: 42px;
  min-height: 42px;
  margin: 0;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  font-size: 0;
  border-radius: 10px;
  background: rgba(255,255,255,.06);
}

body.sidebar-collapsed .nav .brand::before {
  content: "AF";
  color: #fff;
  font-size: 15px;
  font-weight: 800;
}

body.sidebar-collapsed .nav .brand span,
body.sidebar-collapsed .nav a span,
body.sidebar-collapsed .nav .user {
  display: none;
}

body.sidebar-collapsed .nav a {
  width: 42px;
  min-width: 42px;
  max-width: 42px;
  height: 42px;
  min-height: 42px;
  max-height: 42px;
  margin: 0 !important;
  padding: 0 !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0;
  overflow: hidden;
  text-align: center;
}

body.sidebar-collapsed .nav a::before {
  content: attr(data-icon);
  font-size: 21px;
  font-weight: 800;
  color: inherit;
  line-height: 1;
}

.tabs a {
  border: 1px solid var(--line);
  border-radius: 6px !important;
  background: #fff !important;
}
.tabs a.active {
  background: var(--primary) !important;
  border-color: var(--primary);
}

.device-choice {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.device-choice input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.device-choice label {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  border: 1px solid #d6dceb;
  border-radius: 8px;
  background: #fff;
  color: #526089;
  cursor: pointer;
  font-weight: 700;
  font-size: 13px;
  box-shadow: 0 8px 18px rgba(37, 47, 85, .06);
}

.device-choice input:checked + label {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.device-choice label:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.device-choice input:checked + label:hover {
  color: #fff;
}

.search-select {
  position: relative;
  min-width: 150px;
}

.search-select select {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 1px;
  height: 1px;
}

.search-select__button {
  width: 100%;
  min-height: 36px;
  padding: 7px 34px 7px 10px;
  border: 1px solid #cbd3e8 !important;
  border-radius: 6px !important;
  background: #fff !important;
  color: var(--text) !important;
  font-weight: 400;
  text-align: left;
  cursor: text;
  position: relative;
  box-shadow: inset 0 0 0 1px rgba(91, 108, 255, .08), 0 1px 2px rgba(37, 47, 85, .05);
}

.search-select__button::after {
  content: "";
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  position: absolute;
  right: 12px;
  top: 12px;
  transform: rotate(45deg);
}

.search-select__panel {
  display: none;
  position: absolute;
  z-index: 40;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 8px;
}

.search-select.is-open .search-select__panel { display: block; }

.search-select__search {
  width: 100%;
  margin-bottom: 8px;
}

.search-select__options {
  max-height: 230px;
  overflow: auto;
}

.search-select__option {
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}

.search-select__option:hover,
.search-select__option.is-active {
  background: #eef0ff;
  color: var(--primary-strong);
}

.search-select__empty {
  padding: 8px 10px;
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 700px) {
  .search-select { width: 100%; }
  .device-choice { width: 100%; display: grid; grid-template-columns: 1fr 1fr; }
  button, .btn { min-height: 36px; }
  body.sidebar-collapsed { padding: 12px 10px 88px !important; }
  body.sidebar-collapsed .nav {
    width: auto;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    align-items: center;
  }
  body.sidebar-collapsed .nav .brand,
  body.sidebar-collapsed .nav a {
    width: auto;
    height: auto;
    min-height: 0;
    font-size: 13px;
  }
  body.sidebar-collapsed .nav .brand::before,
  body.sidebar-collapsed .nav a::before { content: none; }
  body.sidebar-collapsed .nav a span,
  body.sidebar-collapsed .nav .brand span { display: inline; }
}
