:root {
  --bg: #f7f8fc;
  --surface: #ffffff;
  --surface-alt: #f1f3fa;
  --border: #e3e7f0;
  --border-strong: #cfd6e6;
  --text: #131b2b;
  --muted: #6a7691;
  --primary: #3552f5;
  --primary-dark: #2740cc;
  --primary-soft: #eaeeff;
  --danger: #d33a3a;
  --danger-dark: #b32c2c;
  --success-bg: #e6f7ee;
  --success-text: #1a6b45;
  --error-bg: #fdeaea;
  --error-text: #a72020;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(19, 27, 43, .05);
  --shadow: 0 1px 3px rgba(19, 27, 43, .06), 0 8px 28px rgba(19, 27, 43, .06);
  --sidebar-width: 272px;
  --topbar-height: 62px;
  --control-height: 40px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1 { font-size: 1.55rem; letter-spacing: -.02em; margin: 0; }
h2 { font-size: 1rem; letter-spacing: -.01em; margin: 0 0 1.1rem; }
a { color: var(--primary); }

.muted { color: var(--muted); font-size: .875rem; }

.app {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  gap: .65rem;
  min-height: 100vh;
  padding: .65rem;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: .2rem;
  padding: 1rem .7rem;
  background: linear-gradient(165deg, #1b2a6b 0%, #2740cc 55%, #3552f5 100%);
  border-right: none;
  border-radius: var(--radius);
  box-shadow: 0 2px 6px rgba(19, 27, 43, .08), 0 12px 32px rgba(27, 42, 107, .18);
  position: sticky;
  top: .65rem;
  height: calc(100vh - 1.3rem);
}

.sidebar .brand {
  display: flex;
  align-items: center;
  gap: .6rem;
  font-weight: 650;
  letter-spacing: -.02em;
  color: #fff;
  text-decoration: none;
  padding: .3rem .6rem .9rem;
}
.sidebar .brand svg { flex: none; }

.nav-label {
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: rgba(255, 255, 255, .5);
  font-weight: 600;
  padding: .7rem .6rem .3rem;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .52rem .6rem;
  border-radius: var(--radius-sm);
  color: rgba(255, 255, 255, .78);
  text-decoration: none;
  font-size: .89rem;
  font-weight: 500;
}
.nav-link svg { flex: none; opacity: .75; }
.nav-link:hover { background: rgba(255, 255, 255, .12); color: #fff; }
.nav-link.is-active { background: rgba(255, 255, 255, .18); color: #fff; font-weight: 600; }
.nav-link.is-active svg { opacity: 1; }

.sidebar-footer { margin-top: auto; padding-top: .7rem; border-top: 1px solid rgba(255, 255, 255, .16); }
.sidebar-footer .btn {
  background: transparent;
  border-color: rgba(255, 255, 255, .28);
  color: rgba(255, 255, 255, .85);
}
.sidebar-footer .btn:hover { background: rgba(255, 255, 255, .14); border-color: rgba(255, 255, 255, .4); color: #fff; }

.avatar {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  display: grid;
  place-items: center;
  font-weight: 650;
  font-size: .8rem;
}
.identity-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.identity-text strong { font-size: .85rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.identity-text span { font-size: .74rem; color: var(--muted); }

.main { display: flex; flex-direction: column; min-width: 0; }

.page-head {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding: .7rem .9rem 1rem;
}
.page-head .muted { margin: 0; }

.page-body { flex: 1; padding: 0 .9rem .65rem; display: flex; flex-direction: column; gap: 1rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.5rem 1.6rem;
}
.card-flush { padding: 1.5rem 0 0; }
.card-flush > .card-head, .card-flush > .muted { padding: 0 1.6rem 1.15rem; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.card-head a { font-size: .85rem; text-decoration: none; font-weight: 550; }
.card-head a:hover { text-decoration: underline; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1.1rem; }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.3rem 1.4rem;
  display: flex;
  flex-direction: column;
  gap: .15rem;
}
.stat-value { font-size: 2rem; font-weight: 650; letter-spacing: -.03em; line-height: 1.1; }
.stat-label { color: var(--muted); font-size: .84rem; }

.split { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 1.35rem; align-items: stretch; }
.split > .card { display: flex; flex-direction: column; }

.action-grid { display: flex; flex-direction: column; gap: .7rem; }
.action {
  display: flex;
  align-items: center;
  gap: .85rem;
  padding: .95rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text);
  background: var(--surface-alt);
}
.action:hover { border-color: var(--primary); background: var(--primary-soft); }
.action-icon {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  color: var(--primary);
}
.action-text { display: flex; flex-direction: column; gap: .15rem; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 1.05rem 1.25rem; align-items: end; }
.field { display: flex; flex-direction: column; gap: .38rem; min-width: 0; }
.create-form { display: flex; flex-direction: column; gap: .55rem; }
.create-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr minmax(150px, .7fr) auto;
  gap: .9rem;
  align-items: end;
  width: 100%;
}
.upload-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: .9rem;
  align-items: end;
  width: 100%;
}

.form-message {
  min-height: 1.15rem;
  margin: 0;
  font-size: .82rem;
  color: var(--error-text);
}
.form-message[hidden] { display: block !important; visibility: hidden; }
.field small { line-height: 1.35; }
.field-error { color: var(--error-text); font-size: .8rem; }
input.is-invalid, select.is-invalid { border-color: var(--danger); }
input.is-invalid:focus, select.is-invalid:focus { outline-color: var(--danger); }
.field-action { align-self: end; }
.field-action .btn { width: fit-content; }

label { font-size: .84rem; font-weight: 600; }

input[type="text"], input[type="email"], input[type="password"], input[type="file"], select {
  font: inherit;
  height: var(--control-height);
  padding: 0 .75rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  width: 100%;
}
input[type="file"] { padding: .4rem .6rem; }
input::placeholder { color: #a3adc4; }
input:focus, select:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: var(--primary); }

a.btn { display: inline-block; text-decoration: none; }

.btn {
  font: inherit;
  font-weight: 550;
  cursor: pointer;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  height: var(--control-height);
  padding: 0 1.05rem;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-danger { color: var(--danger); border-color: #f0c9c9; }
.btn-danger:hover { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); padding: .45rem .7rem; }
.btn-ghost:hover { background: var(--surface-alt); color: var(--text); border-color: transparent; }
.btn-small { height: 30px; padding: 0 .68rem; font-size: .8rem; }
.btn-block { width: 100%; display: inline-flex; align-items: center; justify-content: center; gap: .5rem; }

.table-scroll { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .89rem; }
.table th, .table td { text-align: left; padding: .72rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th {
  font-size: .74rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  font-weight: 650;
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--surface-alt); }
.row-disabled { opacity: .5; }
.row-actions { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; justify-content: flex-end; }
.table th:last-child, .table td:last-child { width: 1%; white-space: nowrap; }
.table-actions th:last-child, .table-actions td:last-child { min-width: 22rem; }
.table td:nth-child(2) { white-space: nowrap; }
.inline-form { display: flex; gap: .35rem; align-items: center; }
.inline-form input[type="text"] { width: 152px; height: 30px; padding: 0 .6rem; font-size: .8rem; }

.reset-pop { position: relative; }
.reset-pop summary { list-style: none; cursor: pointer; user-select: none; }
.reset-pop summary::-webkit-details-marker { display: none; }
.reset-pop[open] summary { border-color: var(--primary); color: var(--primary); }
.reset-pop-body {
  position: absolute;
  right: 0;
  top: calc(100% + .4rem);
  z-index: 5;
  padding: .6rem;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}

.cell-user { display: flex; align-items: center; gap: .7rem; }
.cell-user .avatar { width: 30px; height: 30px; font-size: .72rem; }

.badge { display: inline-block; padding: .18rem .55rem; border-radius: 999px; font-size: .73rem; font-weight: 650; }
.badge-admin { background: var(--primary-soft); color: var(--primary-dark); }
.badge-user { background: var(--surface-alt); color: var(--muted); }
.badge-current { background: var(--success-bg); color: var(--success-text); }
.badge-off { background: #f0f2f7; color: var(--muted); }

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .78rem; }

.dot { display: inline-flex; align-items: center; gap: .4rem; font-size: .85rem; }
.dot::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.dot-on::before { background: #27a567; }

.flash { padding: .8rem 1rem; border-radius: var(--radius-sm); font-size: .89rem; margin: 0; border: 1px solid transparent; }
.flash-success { background: var(--success-bg); color: var(--success-text); border-color: #bfe6d2; }
.flash-error { background: var(--error-bg); color: var(--error-text); border-color: #f3c9c9; }

.empty { padding: 2.5rem 1.6rem; text-align: center; color: var(--muted); font-size: .9rem; }

.auth {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 100vh;
  padding: .65rem;
  gap: .65rem;
  background: var(--bg);
}

.auth-visual {
  position: relative;
  overflow: hidden;
  background: linear-gradient(150deg, #1b2a6b 0%, #2740cc 48%, #4a6bff 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 2.5rem 3rem;
  border-radius: var(--radius);
  box-shadow: 0 2px 6px rgba(19, 27, 43, .08), 0 12px 32px rgba(27, 42, 107, .18);
}
.auth-visual > * { position: relative; z-index: 1; }
.auth-visual svg.backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  border-radius: var(--radius);
}

.auth-brand { display: flex; align-items: center; gap: .7rem; font-weight: 650; letter-spacing: -.02em; }

.auth-pitch { max-width: 30rem; }
.auth-pitch h2 {
  font-size: clamp(1.7rem, 2.6vw, 2.5rem);
  line-height: 1.18;
  letter-spacing: -.03em;
  margin: 0 0 1rem;
  font-weight: 650;
}
.auth-pitch p { color: rgba(255, 255, 255, .78); font-size: 1rem; margin: 0; }

.auth-points { display: flex; flex-direction: column; gap: .8rem; margin: 2rem 0 0; padding: 0; list-style: none; }
.auth-points li { display: flex; align-items: center; gap: .7rem; font-size: .92rem; color: rgba(255, 255, 255, .88); }
.auth-points svg { flex: none; opacity: .9; }

.auth-foot { font-size: .8rem; color: rgba(255, 255, 255, .55); }

.auth-form-side {
  display: grid;
  place-items: center;
  padding: 2.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.auth-card { width: 100%; max-width: 27rem; display: flex; flex-direction: column; gap: .45rem; }
.auth-card h1 { font-size: 1.7rem; margin: 0; }
.auth-subtitle { color: var(--muted); font-size: .93rem; margin: .25rem 0 1.4rem; }
.auth-card label { margin-top: .85rem; }
.auth-card .flash { margin-bottom: .35rem; }
.auth-card .btn { margin-top: 1.5rem; padding: .7rem 1.05rem; }
.auth-help { margin-top: 1.4rem; font-size: .82rem; color: var(--muted); text-align: center; }

.simulator-main { padding: 0 .9rem .65rem; display: flex; flex-direction: column; flex: 1; min-height: 0; }
.simulator-frame {
  flex: 1;
  width: 100%;
  min-height: 30rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.solo { position: fixed; inset: 0; display: flex; background: var(--surface); }
.solo-frame { flex: 1; width: 100%; height: 100%; border: none; display: block; }

.solo-logout { position: fixed; right: 1.4rem; bottom: 1.4rem; z-index: 10; }
.btn-float {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  padding: .68rem 1.1rem;
  border-radius: 999px;
  background: var(--danger);
  border: 1px solid var(--danger);
  box-shadow: 0 2px 6px rgba(179, 44, 44, .22), 0 10px 28px rgba(179, 44, 44, .26);
  color: #fff;
  font-weight: 600;
}
.btn-float:hover { background: var(--danger-dark); border-color: var(--danger-dark); color: #fff; }

.centered-shell { display: grid; place-items: center; min-height: 100vh; padding: 2rem; text-align: center; }
.centered-shell .card { max-width: 30rem; display: flex; flex-direction: column; gap: 1rem; align-items: center; }

@media (max-width: 1024px) {
  .auth { grid-template-columns: 1fr; }
  .auth-visual { display: none; }
}

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    gap: .3rem;
    border-right: none;
    border-bottom: none;
    padding: .6rem .9rem;
  }
  .sidebar .brand { padding: 0 1rem 0 0; }
  .nav-label { display: none; }
  .nav-link { padding: .45rem .65rem; }
  .nav-link span { display: none; }
  .sidebar-footer { margin-top: 0; margin-left: auto; padding-top: 0; border-top: none; display: flex; align-items: center; gap: .5rem; }
  .page-head, .page-body, .simulator-main { padding-left: 1.25rem; padding-right: 1.25rem; }
}
