:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --border: #e2e5ec;
  --text: #1f2430;
  --text-muted: #6b7280;
  --primary: #5b7fdb;
  --primary-dark: #4763b8;
  --danger: #d9534f;
  --break-bg: #fdf6e3;
  --break-text: #9a7b1f;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  direction: rtl;
  font-family: Tahoma, "Segoe UI", "Noto Sans Arabic", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-wrap: wrap;
  gap: 10px;
}

.topbar h1 {
  font-size: 1.25rem;
  margin: 0;
}

.topbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  font-family: inherit;
}

.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover { background: var(--primary-dark); }

.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg); }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
}
.btn-danger:hover { background: #fdecea; }

.btn-small { padding: 6px 10px; font-size: 0.85rem; }

main {
  padding: 16px;
}

.schedule-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.grid {
  width: 100%;
  min-width: 680px;
  border-collapse: collapse;
  table-layout: fixed;
}

.grid th, .grid td {
  border: 1px solid var(--border);
  text-align: center;
  vertical-align: middle;
}

.grid thead th {
  padding: 10px 6px;
  font-size: 0.9rem;
  background: var(--surface);
  position: sticky;
  top: 0;
}

.period-col-header {
  width: 110px;
  position: sticky;
  right: 0;
  z-index: 3;
  box-shadow: -2px 0 4px rgba(0, 0, 0, 0.06);
}

.period-label {
  padding: 6px;
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--bg);
  white-space: nowrap;
  position: sticky;
  right: 0;
  z-index: 2;
  box-shadow: -2px 0 4px rgba(0, 0, 0, 0.06);
}

.period-label .period-name {
  display: block;
  font-weight: 600;
  color: var(--text);
}

.period-label .period-time {
  display: block;
  font-size: 0.72rem;
  margin-top: 2px;
}

.break-row td {
  background: var(--break-bg);
  color: var(--break-text);
  font-size: 0.8rem;
  padding: 4px;
}

.class-cell {
  height: 64px;
  padding: 4px;
  cursor: pointer;
  transition: background 0.1s;
  overflow: hidden;
}

.class-cell:hover {
  background: var(--bg);
}

.class-block {
  position: relative;
  height: 100%;
  min-height: 54px;
  border-radius: 6px;
  padding: 6px 8px;
  color: white;
  font-size: 0.8rem;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}

.class-block .subject {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.class-block .meta {
  opacity: 0.9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.72rem;
  min-width: 0;
}

.class-block .note-dot {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: white;
}

.empty-cell-hint {
  color: var(--text-muted);
  font-size: 1.1rem;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 18px 20px 20px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.modal-header h2 {
  font-size: 1.1rem;
  margin: 0;
}

.icon-btn {
  background: none;
  border: none;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  color: var(--text-muted);
}

#classForm label {
  display: block;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 10px;
}

#classForm input[type="text"],
#classForm select {
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--surface);
  font-family: inherit;
}

#classForm input[type="color"] {
  width: 100%;
  margin-top: 4px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px;
}

.row {
  display: flex;
  gap: 12px;
}
.row > label { flex: 1; }

.modal-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 18px;
}
.spacer { flex: 1; }

.notes-section {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.notes-section h3 {
  font-size: 0.95rem;
  margin: 0 0 10px;
}

.notes-list {
  list-style: none;
  padding: 0;
  margin: 0 0 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.notes-list li {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 0.88rem;
  padding: 6px 8px;
  background: var(--bg);
  border-radius: 6px;
}

.notes-list li.done .note-text {
  text-decoration: line-through;
  color: var(--text-muted);
}

.notes-list .note-text {
  flex: 1;
  word-break: break-word;
}

.notes-list .note-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}
.notes-list .note-remove:hover { color: var(--danger); }

.note-form {
  display: flex;
  gap: 8px;
}
.note-form input {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
}

@media (max-width: 480px) {
  .topbar h1 { font-size: 1.05rem; }
  .btn { padding: 7px 10px; font-size: 0.82rem; }
}
