:root {
  --bg: #0f172a;
  --bg-secondary: #111c3a;
  --surface: #162447;
  --card: #1e2d58;
  --primary: #06b6d4;
  --secondary: #f59e0b;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --border: rgba(148, 163, 184, 0.2);
  --radius: 18px;
  --shadow: 0 16px 40px rgba(8, 25, 59, 0.35);
  --accent: rgba(6, 182, 212, 0.2);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: radial-gradient(circle at top left, #1f3a8a, #0f172a 45%);
  color: var(--text);
  min-height: 100vh;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: url('https://www.transparenttextures.com/patterns/cubes.png');
  opacity: 0.08;
  pointer-events: none;
}

.app-shell {
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 1rem;
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.25rem;
}

.app-header,
.app-nav,
.panel,
.card {
  background: linear-gradient(135deg, rgba(30, 45, 88, 0.95), rgba(15, 23, 42, 0.88));
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.app-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem;
  gap: 1rem;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.brand-block h1 {
  margin: 0;
  font-size: 1.5rem;
  letter-spacing: 0.04em;
}

.brand-block img {
  width: 56px;
  height: 56px;
}

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

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.role-select {
  font-size: 0.85rem;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

select,
input,
textarea {
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(148, 163, 184, 0.25);
  color: var(--text);
  border-radius: 12px;
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
  width: 100%;
}

select:focus,
input:focus,
textarea:focus {
  outline: 2px solid var(--primary);
}

textarea {
  resize: vertical;
}

button {
  border: none;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 600;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

button.primary {
  background: linear-gradient(135deg, #0ea5e9, #22d3ee);
  color: #0f172a;
  padding: 0.6rem 1.1rem;
  box-shadow: 0 10px 20px rgba(14, 165, 233, 0.35);
}

button.secondary {
  background: rgba(6, 182, 212, 0.2);
  color: var(--primary);
  padding: 0.55rem 1rem;
  border: 1px solid rgba(6, 182, 212, 0.4);
}

button.ghost {
  background: transparent;
  color: var(--muted);
  padding: 0.5rem;
}

button:hover:not(:disabled) {
  transform: translateY(-2px);
}

.app-nav {
  display: flex;
  overflow-x: auto;
  padding: 0.5rem;
  gap: 0.5rem;
}

.app-nav::-webkit-scrollbar {
  height: 6px;
}

.app-nav::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.3);
  border-radius: 999px;
}

.nav-btn {
  flex: 1;
  min-width: max(150px, 8vw);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem;
  background: rgba(15, 23, 42, 0.6);
  color: var(--muted);
  border: 1px solid transparent;
}

.nav-btn.active {
  background: rgba(14, 165, 233, 0.15);
  border-color: rgba(14, 165, 233, 0.5);
  color: var(--text);
}

.app-main {
  position: relative;
  min-height: 70vh;
}

.panel {
  display: none;
  padding: 1.5rem;
  animation: fadeIn 0.3s ease;
}

.panel.active {
  display: block;
}

.panel.disabled {
  opacity: 0.4;
  pointer-events: none;
}

.form.read-only {
  pointer-events: none;
  opacity: 0.5;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin: 1rem 0;
  padding: 1rem;
  border-radius: var(--radius);
  background: rgba(15, 23, 42, 0.55);
  border: 1px solid rgba(148, 163, 184, 0.15);
}

.form-row {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.form-row label {
  display: flex;
  flex-direction: column;
  font-size: 0.85rem;
  gap: 0.45rem;
  color: var(--muted);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  overflow: hidden;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.4);
}

.data-table thead {
  background: rgba(14, 165, 233, 0.1);
  color: var(--text);
}

.data-table th,
.data-table td {
  padding: 0.75rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.08);
}

.data-table tbody tr:hover {
  background: rgba(14, 165, 233, 0.05);
}

.grid {
  display: grid;
  gap: 1rem;
}

.kpi-grid {
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

.two-col {
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.card {
  padding: 1rem;
  border-radius: var(--radius);
}

.card h3 {
  margin-top: 0;
}

.card p {
  margin: 0.25rem 0;
}

.row-actions {
  display: flex;
  gap: 0.25rem;
  justify-content: flex-end;
}

.muted {
  color: var(--muted);
  margin: 0;
}

.alert-item {
  padding: 0.75rem;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: 12px;
  margin-bottom: 0.75rem;
}

.alert-item:last-child {
  margin-bottom: 0;
}

.alert-title {
  margin: 0 0 0.25rem;
  font-weight: 600;
  color: #fca5a5;
}

.alert-date {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

body[data-role='Viewer'] .form,
body[data-role='Viewer'] [data-export] {
  pointer-events: none;
  opacity: 0.5;
}

body[data-role='Viewer'] .row-actions button[data-action='delete'],
body[data-role='Viewer'] .row-actions button[data-action='edit'] {
  display: none;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 900px) {
  .app-shell {
    padding: 1rem;
  }
  .app-header {
    flex-direction: column;
    align-items: flex-start;
  }
  .header-actions {
    width: 100%;
    justify-content: space-between;
  }
}

@media (max-width: 600px) {
  .app-shell {
    padding: 0.75rem;
  }
  .app-nav {
    gap: 0.35rem;
  }
  .nav-btn {
    min-width: 120px;
    font-size: 0.8rem;
  }
  .panel {
    padding: 1rem;
  }
  .form {
    padding: 0.75rem;
  }
  .form-row {
    grid-template-columns: 1fr;
  }
  .app-header {
    gap: 0.75rem;
  }
  .brand-block {
    flex-direction: column;
    align-items: flex-start;
  }
}
