/* ========== Base ========== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-2: #242836;
  --border: #2e3346;
  --text: #e4e6f0;
  --text-muted: #8b90a5;
  --primary: #4f8cff;
  --primary-hover: #3a75e6;
  --green: #34d399;
  --yellow: #fbbf24;
  --red: #f87171;
  --danger: #ef4444;
  --radius: 8px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
}

html {
  font-size: 14px;
}
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

a {
  color: var(--primary);
}
input,
select,
textarea {
  font-family: var(--font);
  font-size: 0.92rem;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  width: 100%;
  outline: none;
  transition: border-color 0.15s;
}
input:focus,
select:focus {
  border-color: var(--primary);
}

button {
  font-family: var(--font);
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  padding: 8px 16px;
  font-size: 0.88rem;
  font-weight: 500;
  transition:
    background 0.15s,
    transform 0.1s;
}
button:active {
  transform: scale(0.97);
}

/* ========== Buttons ========== */
.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover {
  background: var(--primary-hover);
}
.btn-sm {
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-sm:hover {
  background: var(--border);
  color: var(--text);
}
.btn-danger {
  color: var(--red);
}
.btn-danger:hover {
  background: rgba(248, 113, 113, 0.15);
}

.error-msg {
  color: var(--red);
  font-size: 0.85rem;
  margin-top: 6px;
  min-height: 1.2em;
}

/* ========== Login ========== */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #0f1117 0%, #1a1d27 100%);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px 36px;
  width: 340px;
  text-align: center;
}
.login-card h1 {
  font-size: 1.8rem;
  font-weight: 700;
  margin-bottom: 4px;
}
.login-subtitle {
  color: var(--text-muted);
  margin-bottom: 24px;
  font-size: 0.9rem;
}
.login-card form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-card button {
  margin-top: 6px;
  padding: 10px;
  font-size: 0.95rem;
}

/* ========== Topbar ========== */
#topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}
.topbar-left h1 {
  font-size: 1.15rem;
  font-weight: 700;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
#userEmail {
  color: var(--text-muted);
  font-size: 0.85rem;
}
.role-badge {
  font-size: 0.7rem;
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.5px;
  padding: 3px 8px;
  border-radius: 4px;
  background: rgba(79, 140, 255, 0.15);
  color: var(--primary);
}

/* ========== Tabs ========== */
.tab-bar {
  display: flex;
  gap: 0;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.tab {
  background: transparent;
  color: var(--text-muted);
  padding: 12px 20px;
  border-radius: 0;
  border-bottom: 2px solid transparent;
  font-weight: 500;
}
.tab:hover {
  color: var(--text);
}
.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab-content {
  display: none;
  padding: 24px;
}
.tab-content.active {
  display: block;
}

/* ========== Matrix ========== */
.matrix-controls {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
}
.matrix-controls label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 0.85rem;
}
.matrix-controls input {
  width: 60px;
}
.matrix-wrap {
  overflow-x: auto;
}
#matrixTable {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
#matrixTable th,
#matrixTable td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: center;
  white-space: nowrap;
}
#matrixTable th {
  background: var(--surface-2);
  font-weight: 600;
  position: sticky;
  top: 0;
}
#matrixTable tr.current-week {
  background: rgba(79, 140, 255, 0.08);
}

.cell-green {
  color: var(--green);
}
.cell-yellow {
  color: var(--yellow);
}
.cell-red {
  color: var(--red);
  font-weight: 600;
}
.cell-orders {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ========== Orders ========== */
.orders-layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 20px;
}
@media (max-width: 800px) {
  .orders-layout {
    grid-template-columns: 1fr;
  }
}

.orders-list-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.panel-header h2 {
  font-size: 1rem;
}
.orders-filter {
  margin-bottom: 12px;
}
.orders-filter select {
  width: 100%;
}

.orders-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 68vh;
  overflow-y: auto;
}
.order-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.order-item:hover {
  border-color: var(--primary);
}
.order-item.active {
  border-color: var(--primary);
  background: rgba(79, 140, 255, 0.08);
}
.order-item-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.order-item-title {
  font-weight: 500;
  font-size: 0.9rem;
}
.order-item-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 3px;
}
.status-badge {
  font-size: 0.68rem;
  text-transform: uppercase;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
}
.status-draft {
  background: rgba(251, 191, 36, 0.15);
  color: var(--yellow);
}
.status-complete {
  background: rgba(52, 211, 153, 0.15);
  color: var(--green);
}

.order-detail-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
}
.order-detail-panel h2 {
  font-size: 1rem;
  margin-bottom: 16px;
}
#orderForm {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
#orderForm label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--text-muted);
}
#orderForm label input,
#orderForm label select {
  margin-top: 2px;
}
.section-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 600;
  margin: 4px 0 0 0;
}

.duration-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}
@media (max-width: 700px) {
  .duration-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.schedule-result {
  background: rgba(52, 211, 153, 0.08);
  border: 1px solid rgba(52, 211, 153, 0.25);
  border-radius: 6px;
  padding: 12px;
  font-size: 0.9rem;
}
.form-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 4px;
}

/* ========== Settings ========== */
.settings-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
@media (max-width: 700px) {
  .settings-layout {
    grid-template-columns: 1fr;
  }
}
.settings-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.settings-card h2 {
  font-size: 1rem;
  margin-bottom: 12px;
}
.settings-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}
.settings-item:last-child {
  border-bottom: none;
}
.inline-add {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.inline-add input {
  flex: 1;
}
