/*
 * BIST Alarm Simülatörü — shared stylesheet (no external fonts or CDNs).
 *
 * Classes available to every page:
 *   Layout   .container .page-header (h1 + .actions) .section .card .grid-2 .grid-3
 *            .muted .small .nowrap .text-right .stack (vertical gap) .inline (row gap)
 *   Tables   .table-wrap (scroll box, sticky header) > table.data
 *            td.num / th.num (right-aligned, tabular figures)  tr.total (bold total row)
 *   Numbers  .pos (profit, green) .neg (loss, red)
 *   Badges   .badge + .badge-ok .badge-warn .badge-err .badge-info .badge-muted
 *   Alerts   .alert + .alert-info .alert-success .alert-warning .alert-error (Django message tags)
 *   Forms    .form-grid (label / field rows) .field .helptext .errorlist .form-actions
 *   Buttons  .btn .btn-primary .btn-danger .btn-small; form.inline-form keeps a POST button inline
 *   Stats    .stats > .stat (> .stat-label + .stat-value)
 */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1f2933;
  --muted: #616e7c;
  --border: #d9dee4;
  --border-strong: #b8c0c9;
  --accent: #1f5fbf;
  --accent-dark: #174a96;
  --stripe: #f8f9fb;
  --hover: #eef3fb;
  --pos: #12804a;
  --neg: #c0392b;
  --info-bg: #e8f1fc;   --info-fg: #174a96;
  --ok-bg: #e5f5ec;     --ok-fg: #0f6b3d;
  --warn-bg: #fff4dc;   --warn-fg: #8a5a00;
  --err-bg: #fde8e6;    --err-fg: #a52a1e;
  --radius: 6px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html { font-size: 15px; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.45;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { line-height: 1.25; margin: 0 0 0.6rem; }
h1 { font-size: 1.55rem; }
h2 { font-size: 1.2rem; margin-top: 1.6rem; }
h3 { font-size: 1.05rem; margin-top: 1.2rem; }
p { margin: 0 0 0.8rem; }
code, .mono { font-family: var(--mono); font-size: 0.92em; }

/* ---- top bar ---------------------------------------------------------- */

.topbar { background: #16212e; color: #fff; }
.topbar-inner {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 1.25rem;
  display: flex;
  align-items: center;
  gap: 2rem;
  min-height: 52px;
}
.brand { color: #fff; font-weight: 700; letter-spacing: 0.01em; white-space: nowrap; }
.brand:hover { text-decoration: none; opacity: 0.9; }
.mainnav { display: flex; flex-wrap: wrap; gap: 0.25rem; }
.mainnav a {
  color: #c9d4e0;
  padding: 0.45rem 0.8rem;
  border-radius: var(--radius);
}
.mainnav a:hover { color: #fff; background: rgba(255, 255, 255, 0.08); text-decoration: none; }
.mainnav a.active { color: #fff; background: rgba(255, 255, 255, 0.16); }

/* ---- layout ----------------------------------------------------------- */

.container { max-width: 1320px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1.1rem;
}
.page-header h1 { margin: 0; }
.page-header .actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }

.section { margin-top: 1.75rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  margin-bottom: 1rem;
}
.card > :last-child { margin-bottom: 0; }

.grid-2, .grid-3 { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 900px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

.stack > * + * { margin-top: 0.75rem; }
.inline { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }

.muted { color: var(--muted); }
.small { font-size: 0.87rem; }
.nowrap { white-space: nowrap; }
.text-right { text-align: right; }

/* ---- tables ----------------------------------------------------------- */

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
  max-height: 75vh;
  margin-bottom: 1rem;
}

table.data { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 0.93rem; }
table.data th,
table.data td {
  padding: 0.45rem 0.7rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}
table.data thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #eef1f5;
  border-bottom: 1px solid var(--border-strong);
  font-weight: 600;
  white-space: nowrap;
}
table.data tbody tr:nth-child(even) { background: var(--stripe); }
table.data tbody tr:hover { background: var(--hover); }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data th.num,
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data tr.total td,
table.data tfoot td { font-weight: 700; background: #eef1f5; border-top: 1px solid var(--border-strong); }
table.data th[data-sort] { cursor: pointer; user-select: none; }

/* ---- numbers and badges ---------------------------------------------- */

.pos { color: var(--pos); }
.neg { color: var(--neg); }

.badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
  background: #e4e8ed;
  color: #3e4c59;
}
.badge-ok { background: var(--ok-bg); color: var(--ok-fg); }
.badge-warn { background: var(--warn-bg); color: var(--warn-fg); }
.badge-err { background: var(--err-bg); color: var(--err-fg); }
.badge-info { background: var(--info-bg); color: var(--info-fg); }
.badge-muted { background: #eceff2; color: var(--muted); }

/* ---- alerts (Django message tags: debug, info, success, warning, error) */

.messages { margin-bottom: 1rem; }
.alert {
  padding: 0.7rem 0.95rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  border-left-width: 4px;
  margin-bottom: 0.6rem;
  background: var(--info-bg);
  color: var(--info-fg);
  border-color: #b9d2f3;
}
.alert-info, .alert-debug { background: var(--info-bg); color: var(--info-fg); border-color: #b9d2f3; }
.alert-success { background: var(--ok-bg); color: var(--ok-fg); border-color: #a9dcbf; }
.alert-warning { background: var(--warn-bg); color: var(--warn-fg); border-color: #f0d08a; }
.alert-error { background: var(--err-bg); color: var(--err-fg); border-color: #f1b5ae; }
.alert ul { margin: 0.3rem 0 0; padding-left: 1.2rem; }

/* ---- stat tiles -------------------------------------------------------- */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.7rem 0.9rem;
}
.stat-label { color: var(--muted); font-size: 0.82rem; }
.stat-value { font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---- forms -------------------------------------------------------------- */

.form-grid {
  display: grid;
  grid-template-columns: minmax(180px, 260px) minmax(0, 1fr);
  gap: 0.7rem 1rem;
  align-items: start;
  max-width: 900px;
}
.form-grid > label { padding-top: 0.45rem; font-weight: 600; }
@media (max-width: 700px) { .form-grid { grid-template-columns: 1fr; } }

.field { margin-bottom: 0.9rem; }
.field > label { display: block; font-weight: 600; margin-bottom: 0.25rem; }

input[type="text"], input[type="number"], input[type="date"], input[type="time"],
input[type="search"], input[type="file"], select, textarea {
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 0.4rem 0.55rem;
  max-width: 100%;
}
input[type="file"] { padding: 0.3rem; }
textarea { width: 100%; min-height: 5rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9cbdf0; outline-offset: 0; border-color: var(--accent); }

.helptext { display: block; color: var(--muted); font-size: 0.85rem; margin-top: 0.2rem; }
.errorlist { list-style: none; margin: 0.25rem 0 0; padding: 0; color: var(--neg); font-size: 0.88rem; }
.errorlist.nonfield {
  background: var(--err-bg);
  border: 1px solid #f1b5ae;
  border-radius: var(--radius);
  padding: 0.55rem 0.8rem;
  margin-bottom: 0.8rem;
}
.form-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1.1rem; }

/* ---- buttons ------------------------------------------------------------ */

.btn, button, input[type="submit"] {
  display: inline-block;
  font: inherit;
  font-weight: 600;
  line-height: 1.2;
  padding: 0.5rem 0.95rem;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover, button:hover, input[type="submit"]:hover { background: #f0f2f5; text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn-danger { background: var(--surface); border-color: #e3a49c; color: var(--neg); }
.btn-danger:hover { background: var(--err-bg); }
.btn-small { padding: 0.25rem 0.6rem; font-size: 0.85rem; }
button:disabled, .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }
form.inline-form { display: inline; margin: 0; }

/* Sign-out form in the top bar */
.logout-form { display: flex; align-items: center; gap: 0.5rem; margin-left: auto; }
.logout-user { color: inherit; opacity: 0.85; font-size: 0.9rem; }
