:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-muted: #eef3f6;
  --text: #17202a;
  --muted: #5f6f7d;
  --border: #d8e0e7;
  --accent: #0f6b7a;
  --accent-strong: #094d59;
  --success: #167847;
  --warning: #a16005;
  --danger: #aa2736;
  --shadow: 0 10px 30px rgba(23, 32, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

a {
  color: inherit;
}

input,
select,
textarea,
button {
  font: inherit;
}

.skip-link {
  position: absolute;
  left: 1rem;
  top: -4rem;
  z-index: 100;
  background: var(--text);
  color: #fff;
  padding: 0.6rem 0.8rem;
}

.skip-link:focus {
  top: 1rem;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  padding: 1.2rem;
  background: #17202a;
  color: #f7fbfd;
}

.brand {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 0.8rem;
  align-items: center;
}

.brand-mark {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: 8px;
  background: #d8f0ef;
  color: #0d5058;
  font-weight: 800;
}

.brand-title {
  font-size: 1.05rem;
  font-weight: 800;
}

.brand-subtitle {
  overflow: hidden;
  color: #b8c5ce;
  font-size: 0.78rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-list {
  display: grid;
  gap: 0.35rem;
}

.nav-item {
  border-radius: 8px;
  color: #d8e1e8;
  padding: 0.75rem 0.85rem;
  text-decoration: none;
}

.nav-item:hover,
.nav-item.active {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: auto;
  color: #b8c5ce;
  font-size: 0.85rem;
}

.status-dot {
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 999px;
  background: #5cc28a;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.2rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.92);
}

.topbar h1,
.panel h2 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: 1.5rem;
}

.eyebrow {
  margin: 0 0 0.15rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.topbar-actions,
.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  justify-content: flex-end;
}

.topbar-actions form {
  margin: 0;
}

.role-pill,
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 1.55rem;
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
}

.role-pill {
  background: var(--surface-muted);
  color: var(--muted);
}

.main-content {
  display: grid;
  gap: 1rem;
  padding: 1.5rem;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
}

.metric,
.panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric {
  display: grid;
  gap: 0.35rem;
  padding: 1rem;
}

.metric strong {
  font-size: 2rem;
  line-height: 1;
}

.metric small,
.metric-label,
.panel p,
td small,
.list-row span {
  color: var(--muted);
}

.metric-warning {
  border-color: #e9c46b;
}

.dashboard-grid,
.split-layout,
.auth-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 0.55fr);
  gap: 1rem;
  align-items: start;
}

.panel {
  min-width: 0;
  padding: 1rem;
}

.flash-list {
  display: grid;
  gap: 0.6rem;
  margin-bottom: 1rem;
}

.flash,
.readonly-note {
  border-radius: 6px;
  padding: 0.65rem 0.75rem;
  font-size: 0.9rem;
  font-weight: 700;
}

.flash-error {
  border: 1px solid #e2a1a8;
  background: #fff1f2;
  color: var(--danger);
}

.flash-success {
  border: 1px solid #a3d7bc;
  background: #effaf4;
  color: var(--success);
}

.readonly-note {
  border: 1px solid #c5d5df;
  background: var(--surface-muted);
  color: var(--muted);
}

.panel-wide {
  min-width: 0;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.panel h2 {
  font-size: 1.05rem;
}

.panel p {
  margin: 0.15rem 0 0;
}

.toolbar {
  display: flex;
  gap: 1rem;
  align-items: end;
  justify-content: space-between;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  padding: 1rem;
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.filter-bar label {
  min-width: 190px;
}

.filter-actions {
  display: flex;
  gap: 0.5rem;
  align-items: end;
}

.checkbox-row {
  display: flex;
  gap: 0.55rem;
  align-items: center;
  justify-content: flex-start;
}

.checkbox-row input {
  width: auto;
  min-height: 0;
}

label {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 2.45rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 0.55rem 0.65rem;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 107, 122, 0.18);
  outline: none;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.4rem;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0.55rem 0.8rem;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.button-primary {
  background: var(--accent);
  color: #fff;
}

.button-primary:hover {
  background: var(--accent-strong);
}

.button-secondary {
  border-color: var(--border);
  background: #fff;
  color: var(--text);
}

.button-compact {
  min-height: 1.8rem;
  padding: 0.25rem 0.45rem;
  font-size: 0.78rem;
  line-height: 1.1;
}

.action-stack {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

.action-stack .button {
  flex: 1 1 calc(50% - 0.35rem);
}

.icon-button {
  display: inline-grid;
  min-width: 2.4rem;
  height: 2.4rem;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1;
}

.modal {
  width: min(920px, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  border: 0;
  border-radius: 8px;
  padding: 0;
  background: transparent;
  color: var(--text);
}

.modal::backdrop {
  background: rgba(23, 32, 42, 0.56);
}

.modal-panel {
  max-height: calc(100vh - 2rem);
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(23, 32, 42, 0.28);
  padding: 1rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

.context-box {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 0.35rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-muted);
  padding: 0.8rem;
}

.context-box span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

[hidden] {
  display: none !important;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

.contract-table {
  min-width: 1520px;
}

.device-table {
  min-width: 1520px;
}

.contract-table td,
.device-table td {
  white-space: nowrap;
}

.contract-table th,
.device-table th {
  line-height: 1.25;
  white-space: normal;
}

.contract-table th:last-child,
.contract-table td:last-child,
.device-table th:last-child,
.device-table td:last-child {
  position: sticky;
  right: 0;
  z-index: 1;
  width: 15rem;
  min-width: 15rem;
  background: var(--surface);
  box-shadow: -1px 0 0 var(--border);
}

.contract-table th:last-child,
.device-table th:last-child {
  z-index: 2;
}

th,
td {
  border-bottom: 1px solid var(--border);
  padding: 0.72rem 0.65rem;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

td small {
  display: block;
  margin-top: 0.15rem;
}

.msisdn-cell {
  min-width: 9rem;
}

.msisdn-cell span {
  display: block;
}

.detail-row td {
  border-bottom: 1px solid var(--border);
  padding: 0;
}

.detail-cell {
  background: #f8fafb;
}

.detail-panel {
  display: grid;
  gap: 0.85rem;
  padding: 1rem;
}

.detail-heading p {
  margin: 0.15rem 0 0;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0.75rem;
}

.detail-grid div {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  padding: 0.6rem 0.7rem;
}

.detail-grid span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.detail-grid strong {
  display: block;
  margin-top: 0.2rem;
}

.detail-table-wrap {
  max-width: 100%;
}

.compact-table {
  min-width: 680px;
  background: #fff;
}

.compact-table th,
.compact-table td {
  padding: 0.55rem 0.6rem;
}

.badge-success {
  background: #dff4e8;
  color: var(--success);
}

.badge-warning {
  background: #fff2cf;
  color: var(--warning);
}

.stack-list,
.record-form,
.rule-list {
  display: grid;
  gap: 0.75rem;
}

.list-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.75rem;
}

.list-row:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.list-row strong,
.list-row span {
  display: block;
}

.list-row-meta {
  text-align: right;
  white-space: nowrap;
}

.history-list {
  display: grid;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.history-item {
  display: grid;
  gap: 0.15rem;
  border-left: 3px solid var(--accent);
  background: var(--surface-muted);
  padding: 0.65rem 0.75rem;
}

.history-item span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.history-item p {
  margin: 0;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.assignment-picker {
  display: grid;
  gap: 0.75rem;
}

.assignment-create-panel {
  background: #f8fafb;
}

[data-readonly-form] input:disabled,
[data-readonly-form] select:disabled,
[data-readonly-form] textarea:disabled,
[data-readonly-form] button:disabled {
  cursor: default;
  opacity: 0.78;
}

.upload-box {
  display: grid;
  gap: 0.9rem;
  border: 1px dashed #97acb9;
  border-radius: 8px;
  background: var(--surface-muted);
  padding: 1rem;
}

.upload-box span,
.rule-list span {
  display: block;
  color: var(--muted);
}

.fieldset {
  display: grid;
  gap: 0.75rem;
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.8rem;
}

.fieldset legend {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  padding: 0 0.25rem;
}

.sensitive-fieldset {
  border-color: #e6b96f;
  background: #fff9ed;
}

.multisim-list {
  display: grid;
  gap: 0.75rem;
}

.subrecord-card {
  display: grid;
  gap: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  padding: 0.8rem;
}

.subrecord-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.rule-list span {
  border-left: 3px solid var(--accent);
  background: var(--surface-muted);
  padding: 0.55rem 0.65rem;
}

.auth-layout {
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
}

.footer {
  padding: 0 1.5rem 1.5rem;
  color: var(--muted);
  font-size: 0.82rem;
}

@media (max-width: 1180px) {
  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .detail-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .dashboard-grid,
  .split-layout,
  .auth-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }

  .topbar,
  .toolbar,
  .list-row {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions,
  .toolbar-actions {
    justify-content: flex-start;
  }

  .metric-grid,
  .form-grid,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .main-content {
    padding: 1rem;
  }
}
