:root {
  --bg: #f4f7f4;
  --surface: #ffffff;
  --text: #1b2b1e;
  --muted: #5c6f60;
  --primary: #2e7d32;
  --primary-dark: #1b5e20;
  --danger: #c62828;
  --border: #d8e2d8;
  --warn: #ef6c00;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
[data-theme="dark"] {
  --bg: #121a13;
  --surface: #1d2820;
  --text: #e8f0e9;
  --muted: #9db3a1;
  --primary: #66bb6a;
  --primary-dark: #43a047;
  --danger: #ef5350;
  --border: #2f3d33;
  --warn: #ffb74d;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, "Noto Kufi Arabic", "Noto Sans Arabic", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--primary-dark);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 10;
}
.app-header h1 { font-size: 1.15rem; margin: 0; }
.header-actions { display: flex; gap: 8px; }
.container { max-width: 860px; margin: 0 auto; padding: 16px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat { background: var(--surface); border-radius: var(--radius); padding: 12px; text-align: center; box-shadow: var(--shadow); }
.stat-num { display: block; font-size: 1.5rem; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 0.8rem; color: var(--muted); }
.panel { background: var(--surface); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.panel h2 { margin: 0 0 12px; font-size: 1.05rem; }
.btn {
  font: inherit;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
}
.btn:hover { border-color: var(--primary); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-small { padding: 4px 10px; font-size: 0.85rem; }
.btn-ghost { background: transparent; border-color: transparent; color: inherit; }
.app-header .btn-ghost { color: #fff; }
.op-ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.op { display: flex; align-items: center; gap: 10px; padding: 10px; border: 1px solid var(--border); border-radius: 10px; flex-wrap: wrap; }
.op-type { font-weight: 700; }
.op-field { color: var(--muted); flex: 1; min-width: 120px; }
.op-when { font-size: 0.85rem; }
.op-overdue { border-color: var(--danger); }
.op-overdue .op-when { color: var(--danger); font-weight: 700; }
.op-today { border-color: var(--warn); }
.op-today .op-when { color: var(--warn); font-weight: 700; }
.fields-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.field-card { border: 1px solid var(--border); border-radius: 10px; padding: 12px; }
.field-card h3 { margin: 0 0 6px; font-size: 1rem; }
.field-card p { margin: 4px 0; font-size: 0.9rem; color: var(--muted); }
.card-actions { display: flex; gap: 8px; margin-top: 8px; }
.empty { color: var(--muted); text-align: center; padding: 20px 8px; }
dialog {
  border: none;
  border-radius: var(--radius);
  padding: 20px;
  background: var(--surface);
  color: var(--text);
  width: min(420px, 92vw);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog h3 { margin-top: 0; }
dialog label { display: block; margin-bottom: 12px; }
dialog label span { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 4px; }
dialog input, dialog select {
  width: 100%;
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}
dialog menu { display: flex; justify-content: flex-end; gap: 8px; padding: 0; margin: 16px 0 0; }
.toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 24px;
  display: flex;
  align-items: center;
  gap: 10px;
  opacity: 0;
  transition: transform 0.25s ease, opacity 0.25s ease;
  pointer-events: none;
  z-index: 50;
}

:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
@media (max-width: 560px) {
  .app-header h1 { font-size: 1rem; }
  .panel { padding: 12px; }
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; pointer-events: auto; }

.panel-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.form-error { color: var(--danger); font-size: 0.85rem; margin: 0 0 8px; }
.detail-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.detail-head h3 { margin: 0; }
.detail-meta { color: var(--muted); font-size: 0.9rem; }
.detail-ops { max-height: 40vh; overflow-y: auto; margin-bottom: 12px; }
dialog h4 { margin: 12px 0 6px; font-size: 0.95rem; }
dialog textarea {
  width: 100%;
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  resize: vertical;
}
.op-done { opacity: 0.55; }
.op-done .op-type { text-decoration: line-through; }
.op input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--primary); }

@media print {
  .app-header .header-actions, .panel-actions, .card-actions, .op .btn, .toast, dialog { display: none !important; }
  body { background: #fff; color: #000; }
  .panel, .stat { box-shadow: none; border: 1px solid #ccc; }
  .app-header { position: static; background: #fff; color: #000; border-bottom: 2px solid #000; }
}

.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.chip { font: inherit; font-size: 0.8rem; padding: 4px 12px; border-radius: 16px; border: 1px solid var(--border); background: var(--bg); color: var(--muted); cursor: pointer; }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.search-input { font: inherit; padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); min-width: 140px; flex: 1; }
@media print { .chips, .search-input { display: none !important; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

.group-title { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin: 14px 0 6px; }
.group-overdue { color: var(--danger); }
.group-today { color: var(--warn); }
.panel-actions-secondary { margin-top: 10px; justify-content: flex-end; }
.panel-actions-secondary .btn { font-size: 0.78rem; color: var(--muted); }
@media print { .panel-actions-secondary { display: none !important; } }
