/* ---- Reset & base ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sidebar-bg:     #0f172a;
  --sidebar-text:   #94a3b8;
  --sidebar-active: #3b82f6;
  --sidebar-hover:  #1e293b;
  --brand-color:    #3b82f6;

  --bg:             #f1f5f9;
  --surface:        #ffffff;
  --border:         #e2e8f0;
  --text:           #1e293b;
  --text-muted:     #64748b;

  --green:          #22c55e;
  --red:            #ef4444;
  --yellow:         #f59e0b;
  --blue:           #3b82f6;

  --radius:         8px;
  --shadow:         0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
}

body {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}

/* ---- Layout ---- */
.layout {
  display: flex;
  min-height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px 16px;
  border-bottom: 1px solid #1e293b;
}

.brand-icon {
  width: 30px; height: 30px;
  background: var(--brand-color);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px; color: #fff;
  flex-shrink: 0;
}

.brand-name {
  font-weight: 600;
  font-size: 14px;
  color: #f1f5f9;
  letter-spacing: .01em;
}

.sidebar-section {
  padding: 16px 12px 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: #475569;
}

.sidebar-nav {
  list-style: none;
  padding: 8px 8px;
}

.sidebar-nav li { margin: 2px 0; }

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 13.5px;
  transition: background .12s, color .12s;
}

.sidebar-nav a:hover {
  background: var(--sidebar-hover);
  color: #f1f5f9;
}

.sidebar-nav a.active {
  background: #1d4ed8;
  color: #fff;
}

.sidebar-nav .icon {
  font-size: 15px;
  width: 18px;
  text-align: center;
}

/* ---- Main content ---- */
.main {
  margin-left: 220px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.page-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 18px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.page-header h1 {
  font-size: 18px;
  font-weight: 600;
}

.content {
  padding: 24px 28px;
  flex: 1;
}

/* ---- Cards ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-body { padding: 18px; }

/* ---- Stat grid ---- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
}

.stat-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}

.stat-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ---- Tables ---- */
.table-wrapper {
  overflow-x: auto;
}

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

thead th {
  text-align: left;
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}

tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }

tbody td {
  padding: 11px 14px;
  vertical-align: middle;
}

/* ---- Badges ---- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.badge-green  { background: #dcfce7; color: #15803d; }
.badge-red    { background: #fee2e2; color: #b91c1c; }
.badge-yellow { background: #fef3c7; color: #92400e; }
.badge-blue   { background: #dbeafe; color: #1d4ed8; }
.badge-gray   { background: #f1f5f9; color: #475569; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  border: 1px solid transparent;
  transition: background .12s, border-color .12s;
  line-height: 1;
}

.btn-primary  { background: var(--blue); color: #fff; }
.btn-primary:hover { background: #2563eb; }

.btn-danger   { background: var(--red); color: #fff; }
.btn-danger:hover { background: #dc2626; }

.btn-outline  { background: transparent; border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: #f8fafc; }

.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ---- Forms ---- */
.form-group { margin-bottom: 18px; }

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}

.form-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

.form-control {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  transition: border-color .12s;
  outline: none;
}

.form-control:focus { border-color: var(--blue); }

/* ---- Alert ---- */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 20px;
  border: 1px solid;
}

.alert-error   { background: #fee2e2; border-color: #fca5a5; color: #b91c1c; }
.alert-success { background: #dcfce7; border-color: #86efac; color: #15803d; }
.alert-info    { background: #dbeafe; border-color: #93c5fd; color: #1d4ed8; }

/* ---- Key copy box ---- */
.key-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-family: ui-monospace, monospace;
  font-size: 12px;
  color: var(--text);
  word-break: break-all;
}

.key-box code { flex: 1; }

/* ---- Misc ---- */
.text-muted { color: var(--text-muted); }
.text-mono  { font-family: ui-monospace, monospace; font-size: 12px; }
.mb-4       { margin-bottom: 16px; }
.mb-6       { margin-bottom: 24px; }
.gap-3      { gap: 12px; }
.flex       { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

.section-title {
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}

/* ---- Sidebar footer / user ---- */
.sidebar-footer {
  margin-top: auto;
  padding: 8px 8px 16px;
  border-top: 1px solid #1e293b;
}
.sidebar-user {
  padding: 8px 10px 6px;
  font-size: 11px;
  color: #64748b;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar-signout {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 13px;
  transition: background .12s;
}
.sidebar-signout:hover { background: var(--sidebar-hover); color: #f1f5f9; }

/* ---- View toggle (admin/consumer) ---- */
.view-toggle {
  display: flex;
  gap: 4px;
  margin: 12px 12px 4px;
  padding: 3px;
  background: #1e293b;
  border-radius: 8px;
}
.view-toggle a {
  flex: 1;
  text-align: center;
  padding: 6px 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--sidebar-text);
  text-decoration: none;
  border-radius: 6px;
  transition: background .12s, color .12s;
}
.view-toggle a.on {
  background: var(--brand-color);
  color: #fff;
}

/* ---- Donut chart ---- */
.donut-wrap {
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
}
.donut-legend { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.donut-legend li { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.donut-legend .swatch { width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0; }
.donut-legend .count { font-weight: 700; margin-left: auto; padding-left: 16px; }

/* ---- Port grid ---- */
.port-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}
.port-tile {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  background: var(--surface);
  position: relative;
  overflow: hidden;
}
.port-tile::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
}
.port-tile.available::before { background: var(--green); }
.port-tile.in_use::before    { background: var(--blue); }
.port-tile.used::before      { background: var(--text-muted); }
.port-tile.rotating::before  { background: var(--yellow); }

.port-tile .port-no { font-size: 11px; color: var(--text-muted); font-weight: 600; }
.port-tile .port-num { font-family: ui-monospace, monospace; font-size: 14px; font-weight: 600; margin: 2px 0 6px; }
.port-tile .port-meta { font-size: 11px; color: var(--text-muted); display: flex; justify-content: space-between; }

/* ---- Bar chart (daily usage) ---- */
.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 140px;
  padding-top: 8px;
}
.bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  gap: 6px;
}
.bar {
  width: 100%;
  max-width: 28px;
  background: var(--blue);
  border-radius: 4px 4px 0 0;
  min-height: 2px;
  transition: background .12s;
  position: relative;
}
.bar-col:hover .bar { background: #2563eb; }
.bar-val { font-size: 10px; font-weight: 700; color: var(--text); }
.bar-label { font-size: 10px; color: var(--text-muted); }

/* ---- Responsive table on small screens ---- */
@media (max-width: 900px) {
  .sidebar { width: 56px; }
  .brand-name, .sidebar-section, .sidebar-nav a span, .view-toggle, .sidebar-user { display: none; }
  .main { margin-left: 56px; }
  .content { padding: 16px; }
}
