:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #3b82f6;
  --secondary: #64748b;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --bg: #f8fafc;
  --bg-elevated: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

* {
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
  margin: 0;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  width: 100%;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px;
  width: 100%;
  box-sizing: border-box;
}

.topbar {
  background: #ffffff;
  color: var(--text);
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
  border-bottom: 1px solid var(--border);
}

.topbar .container {
  padding: 20px 32px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.topbar a {
  color: var(--text);
  text-decoration: none;
  transition: color 0.2s;
}

.brand {
  font-weight: 700;
  font-size: 20px;
  letter-spacing: -0.3px;
  color: var(--text);
}

.brand a:hover {
  color: var(--primary);
}

.nav {
  display: flex;
  align-items: center;
  gap: 32px;
}

.nav a {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 14px;
  padding: 8px 0;
  position: relative;
  transition: color 0.2s;
}

.nav a:hover {
  color: var(--text);
}

.nav a::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 0;
  height: 2px;
  background: var(--primary);
  transition: width 0.3s ease;
}

.nav a:hover::after {
  width: 100%;
}

.nav-dropdown {
  position: relative;
  display: inline-block;
}

.nav-dropdown-content {
  display: none;
  position: absolute;
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  min-width: 160px;
  z-index: 1000;
  margin-top: 4px;
  top: 100%;
  left: 0;
}

.nav-dropdown-content a {
  display: block;
  padding: 12px 16px;
  text-decoration: none;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  transition: background 0.2s;
}

.nav-dropdown-content a:last-child {
  border-bottom: none;
}

.nav-dropdown-content a:hover {
  background: var(--bg);
  color: var(--primary);
}

.nav-dropdown-content a::after {
  display: none;
}

h1 {
  font-size: 36px;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 8px 0;
  letter-spacing: -0.8px;
  line-height: 1.2;
}

h2 {
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 24px 0;
  letter-spacing: -0.4px;
}

h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin: 0;
}

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s, border-color 0.2s;
}

.card:hover {
  box-shadow: var(--shadow-md);
  border-color: #cbd5e1;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 24px;
  margin: 32px 0;
}

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 24px;
  margin: 40px 0;
}

.kpi {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  box-shadow: var(--shadow-sm);
  position: relative;
  transition: all 0.2s;
  border-left: 4px solid var(--primary);
}

.kpi:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.kpi.warning {
  border-left-color: var(--warning);
}

.kpi.success {
  border-left-color: var(--success);
}

.kpi.danger {
  border-left-color: var(--danger);
}

.kpi.secondary {
  border-left-color: var(--secondary);
}

.kpi .label {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 12px;
  display: block;
}

.kpi .value {
  font-size: 42px;
  font-weight: 700;
  margin: 0;
  letter-spacing: -1.5px;
  color: var(--text);
  line-height: 1;
}

.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-elevated);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}

.table th,
.table td {
  padding: 18px 24px;
  text-align: left;
  vertical-align: middle;
}

.table th {
  background: #f8fafc;
  font-weight: 600;
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  border-bottom: 2px solid var(--border);
}

.table tbody tr {
  border-bottom: 1px solid #f1f5f9;
  transition: background 0.15s;
}

.table tbody tr:last-child {
  border-bottom: none;
}

.table tbody tr:hover {
  background: #f8fafc;
}

.table tbody tr.urgent {
  background: #fffbeb;
  border-left: 3px solid var(--warning);
}

.table tbody tr.urgent:hover {
  background: #fef3c7;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--primary);
  color: #fff;
  padding: 12px 24px;
  border-radius: 8px;
  border: 0;
  cursor: pointer;
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
  transition: all 0.2s;
  box-shadow: var(--shadow-sm);
  letter-spacing: 0.1px;
}

.btn:hover {
  background: var(--primary-dark);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn.secondary {
  background: var(--secondary);
  color: #fff;
}

.btn.secondary:hover {
  background: #475569;
}

.btn.success {
  background: var(--success);
}

.btn.warning {
  background: var(--warning);
  color: #fff;
}

.btn.danger {
  background: var(--danger);
}

.btn-group {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin: 32px 0;
}

input,
select,
textarea {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 8px 0 16px;
  box-sizing: border-box;
  font-family: inherit;
  font-size: 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
  background: var(--bg-elevated);
  color: var(--text);
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.muted {
  color: var(--text-muted);
  font-size: 14px;
}

.hint {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 8px;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

.img {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.footer {
  padding: 40px 0;
  color: var(--text-muted);
  text-align: center;
  font-size: 13px;
  border-top: 1px solid var(--border);
  margin-top: 80px;
}

.list {
  margin: 0;
  padding-left: 20px;
}

.row {
  margin: 20px 0;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}

.badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 6px;
  background: #f1f5f9;
  color: var(--text);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge.success {
  background: #d1fae5;
  color: #065f46;
}

.badge.warning {
  background: #fef3c7;
  color: #92400e;
}

.badge.danger {
  background: #fee2e2;
  color: #991b1b;
}

.status-indicator {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  background: #f1f5f9;
  color: var(--text);
}

.status-indicator.success {
  background: #d1fae5;
  color: #065f46;
}

.status-indicator.warning {
  background: #fef3c7;
  color: #92400e;
}

.status-indicator.danger {
  background: #fee2e2;
  color: #991b1b;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.status-dot.success {
  background: var(--success);
}

.status-dot.warning {
  background: var(--warning);
}

.status-dot.danger {
  background: var(--danger);
}

@media (max-width: 900px) {
  .grid,
  .two-col {
    grid-template-columns: 1fr;
  }

  .kpis {
    grid-template-columns: 1fr;
  }

  .container {
    padding: 16px;
  }

  h1 {
    font-size: 28px;
  }
}

@media (max-width: 768px) {
  .container {
    padding: 12px;
    max-width: 100%;
    width: 100%;
    box-sizing: border-box;
  }

  .topbar .container {
    padding: 16px 12px;
    box-sizing: border-box;
  }

  /* Make tables horizontally scrollable on mobile */
  .table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -12px;
    padding: 0 12px;
    width: calc(100% + 24px);
    max-width: calc(100vw - 24px);
    position: relative;
  }
  
  /* Ensure table-wrapper inside cards doesn't break out */
  .card .table-wrapper {
    margin: 0 -16px;
    padding: 0 16px;
    width: calc(100% + 32px);
    max-width: calc(100% + 32px);
  }

  .table {
    min-width: 600px; /* Ensure table doesn't get too compressed */
    font-size: 14px;
  }

  .table th,
  .table td {
    padding: 12px 16px;
  }

  .card {
    padding: 16px;
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  .grid {
    gap: 16px;
    margin: 24px 0;
    grid-template-columns: 1fr;
    width: 100%;
    max-width: 100%;
  }

  /* Ensure all form elements fit */
  input, textarea, select {
    max-width: 100%;
    box-sizing: border-box;
  }
}

/* Portrait-specific fixes for mobile */
@media (max-width: 768px) and (orientation: portrait) {
  .container {
    padding: 8px;
  }

  .topbar .container {
    padding: 12px 8px;
  }

  .card {
    padding: 12px;
  }

  .table-wrapper {
    margin: 0 -8px;
    padding: 0 8px;
    width: calc(100% + 16px);
    max-width: calc(100vw - 16px);
  }
  
  /* Ensure table-wrapper inside cards doesn't break out in portrait */
  .card .table-wrapper {
    margin: 0 -12px;
    padding: 0 12px;
    width: calc(100% + 24px);
    max-width: calc(100% + 24px);
  }

  .table th,
  .table td {
    padding: 10px 12px;
    font-size: 13px;
  }

  h1 {
    font-size: 24px;
  }

  h2 {
    font-size: 18px;
  }
}
