/* Formalizer UI — RTL Persian, Vazir font.
   Theme: coffee brown (قهوه‌ای) — chosen to stand apart from the sibling
   apps (summarizer blue, OCR violet, transcriber crimson); deliberately not
   blue/teal/violet/crimson/green/orange.
   Layering follows the family's legacy "grid → white card" look:
   body #795548 · grid #d7ccc8 + border #a1887f · output #efebe9
   primary button #795548/#a1887f · cancel button #eec17a/#e6af08/#79522c · accent #a1662f */

@font-face {
  font-family: 'vazir';
  src: url('/static/fonts/Vazir.woff2') format('woff2'),
       url('/static/fonts/Vazir.woff') format('woff'),
       url('/static/fonts/Vazir.ttf') format('truetype');
  font-weight: 400;
  font-style: normal;
}

:root {
  --body-bg: #795548;      /* coffee brown page background */
  --grid-bg: #d7ccc8;      /* warm beige grid layer */
  --grid-border: #a1887f;  /* grid border (brown 300) */
  --panel: #a1887f;        /* panel accents */
  --surface: #ffffff;      /* white card */
  --output-bg: #efebe9;    /* warm cream output box */
  --border: #bcaaa4;       /* neutral input border */
  --text: #000000;
  --muted: #8d7b6e;        /* warm gray-brown */
  --accent: #a1662f;       /* copper */
  --accent-bright: #c79a63;
  --accent-dark: #7d4a21;  /* deep coffee */
  --primary: #795548;      /* main action button (matches page bg) */
  --primary-border: #a1887f;
  --secondary: #eec17a;    /* cancel button (carried from summarizer) */
  --secondary-border: #e6af08;
  --secondary-text: #79522c;
  --fieldset-bg: #7d4a21;  /* legend chips / copy button */
  --danger: #c0392b;
  --radius: 12px;
  --shadow: 0 2px 6px rgba(0, 0, 0, 0.1); /* card shadow */
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--body-bg);
  color: var(--text);
  font-family: 'vazir', 'Segoe UI', Tahoma, sans-serif;
  line-height: 1.8;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}

/* ---------- header ---------- */

.app-header { text-align: center; margin: 8px 0 24px; }
.app-header h1 { margin: 0; font-size: 1.6rem; color: #ffffff; }

/* ---------- cards (legacy layered look: gray grid → white card) ---------- */

.card {
  background: var(--grid-bg);
  border: 3px solid var(--grid-border);
  border-radius: 15px;
  padding: 4px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.card-inner {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
}

/* ---------- controls ---------- */

.controls-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.controls-grid label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--muted);
}

select, textarea {
  font-family: inherit;
  font-size: 1rem;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}

select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}

.field-label {
  display: block;
  margin: 4px 0 8px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--fieldset-bg);  /* nod to the old blue legend chips */
}

textarea {
  width: 100%;
  min-height: 140px;
  resize: none;
  overflow: hidden;          /* never show a scrollbar — the box grows to fit */
  overflow-wrap: anywhere;   /* long unbroken strings wrap instead of scrolling */
}

/* ---------- actions ---------- */

.actions { display: flex; gap: 12px; margin-top: 14px; }

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

.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary {
  background: var(--primary);
  border: 2px solid var(--primary-border);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-dark); }

.btn-secondary {
  background: var(--secondary);
  border: 2px solid var(--secondary-border);
  color: var(--secondary-text);
}
.btn-secondary:hover:not(:disabled) { background: #e6b25f; }

.btn-copy {
  background: var(--fieldset-bg);
  border: 1px solid var(--grid-border);
  color: #fff;
  font-size: 0.8rem;
  padding: 4px 16px;
  border-radius: 6px;
}
.btn-copy:hover:not(:disabled) { background: var(--accent-dark); }

.btn-share {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.8rem;
  padding: 3px 10px 3px 8px;
  border-radius: 6px;
  cursor: pointer;
}
.btn-share:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-share:hover:not(:disabled) { border-color: var(--accent-dark); }
.btn-share .share-icon { width: 18px; height: 18px; object-fit: contain; border-radius: 4px; }

/* ---------- status / error ---------- */

.status { min-height: 1.5em; color: var(--muted); font-size: 0.9rem; margin: 12px 0 0; }
.error { color: var(--danger); font-size: 0.9rem; margin: 12px 0 0; }

/* ---------- output (single reconstructed-text box) ---------- */

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

.output-header h2 { margin: 0; font-size: 1.05rem; }

.output-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.log-file {
  display: block;
  margin: 10px 2px 0;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.72rem;
  color: var(--muted);
  direction: ltr;
  unicode-bidi: isolate;
  word-break: break-all;     /* long filenames wrap instead of breaking layout */
  overflow-wrap: anywhere;
}

.output {
  background: var(--output-bg);
  border-radius: 10px;
  min-height: 120px;         /* no max-height/scrollbar: box grows to its content */
  padding: 20px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 1.0em;
  line-height: 1.6rem;
}

/* blinking caret while the stream is active */
.output.is-streaming::after {
  content: '';
  display: inline-block;
  width: 2px;
  height: 1.1em;
  margin-inline-start: 4px;
  vertical-align: text-bottom;
  background: var(--accent);
  animation: blink 1s steps(2, start) infinite;
}

@keyframes blink { to { visibility: hidden; } }

/* ---------- responsive ---------- */

@media (max-width: 600px) {
  .container { padding: 12px 8px 40px; }
  .controls-grid { grid-template-columns: 1fr 1fr; }
  .output-actions { flex-wrap: wrap; } /* buttons + log keep their own line */
}
