@font-face {
  font-family: 'TetraAzahar';
  src: url('/fonts/TetraAzahar.otf') format('opentype');
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --bg: #0c0c0e;
  --surface: #141417;
  --surface-2: #1b1b1f;
  --line: #2a2a30;
  --line-strong: #3a3a42;
  --text: #f3f3f4;
  --muted: #9a9aa3;
  --accent: #ff9100;
  --accent-ink: #171107;
  --danger: #ff6b5e;
  --ok: #4cc38a;
  --radius: 10px;
  --font: TetraAzahar, Almarai, Tahoma, Arial, sans-serif;
  --latin: Manrope, Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 var(--font);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p { margin: 0; }
.muted { color: var(--muted); font-size: 13px; }

label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 13px;
}

input, textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  padding: 10px 12px;
  transition: border-color .15s, background-color .15s;
}
input:hover { border-color: var(--line-strong); }
input:focus, textarea:focus { outline: none; border-color: var(--accent); }
::placeholder { color: var(--muted); opacity: .7; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input:focus-visible, textarea:focus-visible { outline: none; }

kbd {
  font: 11px var(--latin);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
}

/* Buttons */
.btn {
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  font: 700 14px var(--font);
  min-height: 42px;
  padding: 9px 18px;
  transition: background-color .15s, border-color .15s;
}
.btn:hover { background: #26262b; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #ffa22e; border-color: #ffa22e; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--danger); }
.btn.wide { width: 100%; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  background: transparent;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Logo */
.logo {
  color: var(--accent);
  font: 800 34px/1 var(--latin);
  letter-spacing: -1px;
  text-align: center;
}
.logo small {
  display: block;
  margin-top: 5px;
  font: 800 10px var(--latin);
  letter-spacing: 3.6px;
}
.logo-sm { font-size: 21px; letter-spacing: -.5px; }
.logo-sm small { font-size: 7px; letter-spacing: 2.2px; margin-top: 3px; }

/* Sign-in */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: 3px solid var(--accent);
  border-radius: 14px;
  padding: 34px 28px 28px;
}
.login-card h1 { font-size: 19px; text-align: center; margin: 18px 0 26px; }
.login-card label { margin-top: 16px; }
.login-card .btn { margin-top: 18px; }
.form-error { color: var(--danger); font-size: 13px; min-height: 0; }
.form-error:not(:empty) { margin-top: 10px; }
.form-error.ok { color: var(--ok); }
.hint { color: var(--muted); font-size: 12px; text-align: center; margin-top: 14px; }

/* App layout */
.app {
  display: grid;
  height: 100%;
  grid-template-columns: 280px minmax(0, 1fr);
  grid-template-rows: 64px minmax(0, 1fr);
  grid-template-areas: "top top" "side main";
}

.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.save-state {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-inline-start: auto;
  color: var(--muted);
  font-size: 13px;
  min-width: 0;
}
.save-state .dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.save-state[data-state="saving"] .dot { background: var(--accent); animation: pulse 1s infinite; }
.save-state[data-state="offline"] .dot { background: var(--danger); }
.save-state[data-state="offline"] { color: var(--text); }
@keyframes pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .save-state .dot { animation: none !important; } }

.account-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: none;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  font: 700 14px var(--font);
  min-height: 38px;
  padding: 4px 12px;
}
.account-btn:hover { background: var(--surface-2); }
.account-btn svg { width: 15px; height: 15px; color: var(--muted); }

/* Sidebar */
.sidebar {
  grid-area: side;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 16px;
  background: var(--surface);
  border-inline-end: 1px solid var(--line);
}
.sidebar h2 { color: var(--muted); font-size: 12px; font-weight: 700; margin: 20px 4px 8px; }
.report-list { flex: 1; overflow-y: auto; margin: 0 -6px; padding: 0 6px; }
.report-item {
  display: block;
  width: 100%;
  background: transparent;
  border: 0;
  border-radius: 8px;
  color: inherit;
  cursor: pointer;
  font: inherit;
  padding: 10px 12px;
  text-align: start;
  margin-bottom: 2px;
}
.report-item:hover { background: var(--surface-2); }
.report-item[aria-current="true"] { background: var(--surface-2); box-shadow: inset -3px 0 0 var(--accent); }
.report-item-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.report-item-date { font-weight: 700; font-size: 14px; }
.report-item-tag { flex: none; color: var(--muted); font-size: 11px; }
.report-item-tag.today { color: var(--accent); }
.report-item-preview {
  color: var(--muted);
  font-size: 12.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.scrim { position: fixed; inset: 0; background: #0009; z-index: 20; }

/* Editor */
.editor { grid-area: main; overflow-y: auto; padding: 36px 24px 56px; }
.doc { max-width: 760px; margin: 0 auto; }
.doc-head h1 { font-size: 27px; font-weight: 800; line-height: 1.3; }
.doc-head p { margin-top: 2px; font-size: 14px; }

.fields {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 14px;
  margin-top: 26px;
  padding-bottom: 26px;
  border-bottom: 1px solid var(--line);
}
#sender { font-weight: 700; }
input[type="date"] { font-family: var(--latin); font-weight: 700; }

.points-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 24px 0 8px;
}
.points-head h2 { font-size: 17px; font-weight: 800; }

.point {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) 34px;
  align-items: start;
  border-bottom: 1px solid var(--line);
  padding: 8px 0;
}
.point:focus-within { border-bottom-color: var(--accent); }
.point-number {
  color: var(--accent);
  font: 800 16px var(--latin);
  padding-top: 11px;
}
.point textarea {
  display: block;
  background: transparent;
  border: 0;
  border-radius: 0;
  font-size: 16px;
  line-height: 1.9;
  min-height: 48px;
  overflow: hidden;
  padding: 7px 0;
  resize: none;
}
.point .remove { width: 34px; height: 34px; margin-top: 6px; opacity: 0; }
.point:hover .remove, .point:focus-within .remove, .point .remove:focus-visible { opacity: 1; }
.point .remove svg { width: 16px; height: 16px; }
@media (hover: none) { .point .remove { opacity: 1; } }

.add-point {
  background: transparent;
  border: 0;
  color: var(--accent);
  cursor: pointer;
  font: 700 14px var(--font);
  min-height: 44px;
  padding: 10px 0;
  margin-top: 4px;
}
.add-point:hover { text-decoration: underline; text-underline-offset: 3px; }

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-top: 28px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}
.actions .danger { margin-inline-start: auto; }

/* Dialogs */
.dialog {
  width: min(460px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  color: var(--text);
  padding: 20px 22px 22px;
}
.dialog::backdrop { background: #000a; }
.dialog-wide { width: min(780px, calc(100vw - 32px)); height: calc(100dvh - 48px); padding: 0; overflow: hidden; }
.dialog-wide[open] { display: flex; flex-direction: column; }
.dialog-wide .dialog-head { padding: 12px 18px; border-bottom: 1px solid var(--line); margin: 0; }
.dialog-wide iframe { flex: 1; width: 100%; border: 0; background: var(--bg); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.dialog-head h2 { font-size: 17px; font-weight: 800; }

.stack { padding: 14px 0 18px; border-top: 1px solid var(--line); }
.stack h3 { font-size: 14px; font-weight: 800; margin-bottom: 12px; }
.stack label { margin-top: 10px; }
.stack > .btn { margin-top: 14px; }

.user-list { list-style: none; margin: 0 0 12px; padding: 0; }
.user-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 7px 0;
  border-bottom: 1px solid var(--line);
  font-weight: 700;
}
.link-btn {
  background: none;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  font: 13px var(--font);
  min-height: 32px;
  padding: 2px 6px;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.link-btn:hover { color: var(--text); }
.user-form { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: end; }
.user-form label { margin-top: 0; }

/* Toast */
.toast {
  position: fixed;
  z-index: 40;
  inset-block-end: 22px;
  inset-inline-start: 50%;
  transform: translateX(50%);
  display: flex;
  gap: 14px;
  align-items: center;
  max-width: calc(100vw - 32px);
  background: #26262b;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  box-shadow: 0 10px 34px #0009;
  padding: 10px 16px;
  font-size: 14px;
}
.toast-action {
  flex: none;
  background: none;
  border: 0;
  color: var(--accent);
  cursor: pointer;
  font: 700 14px var(--font);
  min-height: 32px;
}

/* Phone */
.only-mobile { display: none; }
@media (max-width: 820px) {
  .only-mobile { display: inline-grid; }
  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "top" "main";
    grid-template-rows: 58px minmax(0, 1fr);
  }
  .topbar { padding: 0 12px; gap: 8px; }
  .sidebar {
    position: fixed;
    z-index: 30;
    inset-block: 0;
    inset-inline-start: 0;
    width: min(300px, 84vw);
    transform: translateX(100%);
    transition: transform .2s ease-out;
    visibility: hidden;
  }
  .sidebar.open { transform: none; visibility: visible; }
  .editor { padding: 22px 16px 40px; }
  .doc-head h1 { font-size: 23px; }
  .fields { grid-template-columns: 1fr; }
  .points-head .muted { display: none; }
  .actions .btn { flex: 1 1 auto; }
  .actions .primary { flex-basis: 100%; }
  .actions .danger { margin-inline-start: 0; }
  .user-form { grid-template-columns: 1fr; }
}
@media (max-width: 420px) {
  .logo-sm small { display: none; }
  .account-btn { max-width: 96px; }
  .account-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
