:root {
  --bg: #f3f6fb;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #5d6b82;
  --line: #d6deea;
  --primary: #0d6fb8;
  --primary-dark: #0a5f9e;
  --accent: #16b6c9;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Segoe UI, Tahoma, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  background: linear-gradient(90deg, var(--primary), var(--accent));
  color: #fff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}
.topbar-inner {
  padding: 10px 16px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 16px;
  align-items: center;
}
.brand { font-weight: 700; white-space: nowrap; }
.nav { display: flex; gap: 8px; overflow-x: auto; }
.nav-link {
  color: #e8f3ff;
  text-decoration: none;
  padding: 8px 10px;
  border-radius: 8px;
  white-space: nowrap;
}
.nav-link:hover, .nav-link.is-active { background: rgba(255, 255, 255, 0.2); color: #fff; }
.userbox, .userbox a { color: #fff; font-size: 14px; }

.container { padding: 16px; }
.page-head h1 { margin: 0; font-size: 24px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }

.cards { display: grid; gap: 12px; margin: 16px 0; }
.cards.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  box-shadow: 0 2px 6px rgba(12, 28, 53, 0.04);
}
.card h2, .card h3 { margin: 0 0 10px; }
.card strong { font-size: 24px; }

.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; min-width: 640px; }
th, td { border-bottom: 1px solid var(--line); padding: 10px; text-align: left; font-size: 14px; }
th { background: #f8fbff; color: #42536f; }

.grid-week {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}
.slot {
  border: 1px solid #8de8d0;
  background: #dffff4;
  border-radius: 8px;
  padding: 10px;
}

.form-row { display: grid; gap: 10px; grid-template-columns: repeat(3, minmax(0, 1fr)); margin-bottom: 10px; }
.form-row.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-row.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input, textarea, button {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
  font: inherit;
}
textarea { min-height: 88px; resize: vertical; }
.badges { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.badge { background: #e9f4ff; color: #2a4f79; border-radius: 16px; padding: 6px 10px; font-size: 13px; }

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at top, #d6ecff, #edf4fb 45%, #f5f8fc);
}
.login-card {
  width: min(420px, calc(100vw - 24px));
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
}
.form-grid { display: grid; gap: 8px; }
button {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  cursor: pointer;
}
button:hover { background: var(--primary-dark); }
.alert { border-radius: 8px; padding: 10px; margin-bottom: 10px; }
.alert-error { background: #ffe7e7; border: 1px solid #ffc8c8; color: #8f2b2b; }
.alert-success { background: #e8f8ed; border: 1px solid #bde7c9; color: #1f6b3a; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}

.toolbar .spacer { flex: 1; }

.inline-form {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.inline-form input,
.inline-form select {
  width: auto;
  min-width: 180px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.stat-box {
  background: #f6f9ff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
}

.stat-box .label { color: var(--muted); font-size: 13px; }
.stat-box .value { font-size: 24px; font-weight: 700; }

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.tab-link {
  display: inline-block;
  text-decoration: none;
  color: #2a4365;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: #fff;
}

.tab-link.is-active { background: #e9f3ff; border-color: #b8d8ff; }

.pagination {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.pagination a {
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 10px;
  color: #2a4365;
  background: #fff;
}

.pagination a.current { background: #dcecff; border-color: #9bc5ff; }

.toast {
  position: sticky;
  top: 12px;
  z-index: 20;
  margin-bottom: 12px;
  border-radius: 10px;
  padding: 10px 12px;
  border: 1px solid #b8f3d0;
  background: #e8fff1;
  color: #1b6135;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
}

.field {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafcff;
  padding: 10px;
}

.field .k { color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.field .v { font-weight: 600; word-break: break-word; }

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.appointment-card {
  background: #ffffff;
  border: 1px solid #d6e4ff;
  border-left: 4px solid var(--primary);
  border-radius: 10px;
  padding: 12px;
  transition: all 0.2s;
}

.appointment-card:hover {
  box-shadow: 0 4px 12px rgba(13, 111, 184, 0.15);
  transform: translateY(-2px);
}

.appointment-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid #e8f0ff;
}

.appointment-time {
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
}

.appointment-body {
  display: grid;
  gap: 6px;
  font-size: 14px;
  margin-bottom: 10px;
}

.appointment-body > div {
  padding: 4px 0;
}

.onec-form {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: #f9fbff;
}

.onec-top-row,
.onec-name-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 8px;
}

.onec-name-row {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.onec-input {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 8px;
}

.onec-input span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.onec-input strong {
  font-size: 14px;
  font-weight: 600;
}

.onec-subtabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 8px 0;
  margin-bottom: 10px;
}

.onec-subtabs span {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 5px 8px;
  background: #fff;
  color: #3f5169;
  font-size: 12px;
}

.onec-subtabs .onec-subtab {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 5px 8px;
  background: #fff;
  color: #3f5169;
  font-size: 12px;
  text-decoration: none;
}

.onec-subtabs span.is-active {
  background: #e9f3ff;
  border-color: #b8d8ff;
}

.onec-subtabs .onec-subtab.is-active {
  background: #e9f3ff;
  border-color: #b8d8ff;
}

.onec-columns {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 10px;
}

.onec-right {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
}

.onec-right h3 {
  margin: 0 0 8px;
  font-size: 15px;
}

.flag-list {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}

.flag-list label {
  margin: 0;
  color: var(--text);
}

.flag-list input[type="checkbox"] {
  width: auto;
  margin-right: 6px;
}

.onec-events {
  display: grid;
  gap: 6px;
}

.onec-event-item {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f8fbff;
  padding: 6px;
}

.onec-event-item .d {
  font-size: 12px;
  color: var(--muted);
}

.onec-event-item .t {
  font-size: 13px;
  font-weight: 600;
}

.appointment-notes {
  background: #fffbea;
  border: 1px solid #ffe9a8;
  border-radius: 6px;
  padding: 8px;
  margin-top: 6px;
  font-size: 13px;
  color: #6b5c00;
}

.appointment-footer {
  display: flex;
  justify-content: flex-end;
  padding-top: 8px;
  border-top: 1px solid #e8f0ff;
}

.card-link {
  color: var(--primary);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  transition: color 0.2s;
}

.card-link:hover {
  color: var(--primary-dark);
  text-decoration: underline;
}

.week-scheduler {
  overflow: auto;
}

.week-scheduler-grid {
  --grid-height: 784px;
  --slot-height: 28px;
  display: grid;
  grid-template-columns: 72px repeat(7, minmax(160px, 1fr));
  min-width: 1200px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.time-col-head,
.day-col-head {
  height: 44px;
  border-bottom: 1px solid var(--line);
  background: #f8fbff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  color: #42536f;
}

.day-col-head {
  border-left: 1px solid var(--line);
}

.time-col,
.day-col {
  position: relative;
  height: var(--grid-height);
}

.time-col {
  border-right: 1px solid var(--line);
  background: #f8fbff;
}

.time-label {
  position: absolute;
  left: 6px;
  transform: translateY(-7px);
  font-size: 11px;
  color: #6a7a91;
}

.day-col {
  border-left: 1px solid var(--line);
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent calc(var(--slot-height) - 1px),
    #edf2fb calc(var(--slot-height) - 1px),
    #edf2fb var(--slot-height)
  );
}

.week-appointment {
  position: absolute;
  left: 6px;
  right: 6px;
  display: block;
  border: 1px solid #8cc2ff;
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  background: #eaf4ff;
  color: #1f3b5a;
  text-decoration: none;
  padding: 4px 6px;
  overflow: hidden;
}

.week-appointment .t {
  font-size: 11px;
  font-weight: 700;
}

.week-appointment .c {
  font-size: 12px;
  font-weight: 600;
}

.week-appointment .m {
  font-size: 11px;
  color: #42536f;
}

@media (max-width: 980px) {
  .topbar-inner { grid-template-columns: 1fr; }
  .userbox { font-size: 13px; }
  .cards.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .calendar-grid { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
  .onec-top-row,
  .onec-name-row,
  .onec-columns { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .container { padding: 10px; }
  .cards.four, .form-row, .form-row.two, .form-row.three { grid-template-columns: 1fr; }
  .page-head h1 { font-size: 20px; }
  .nav { padding-bottom: 6px; }
  .inline-form input,
  .inline-form select,
  .inline-form button { width: 100%; }
  .calendar-grid { grid-template-columns: 1fr; }
}
