:root {
  --bg: #0f1419;
  --bg-2: #171e26;
  --panel: #1c2530;
  --line: #2a3644;
  --text: #e8eef5;
  --muted: #8fa0b3;
  --accent: #e8a317;
  --accent-2: #f0c14d;
  --danger: #e85d4c;
  --ok: #3cb89a;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --radius: 14px;
  --font: "IBM Plex Sans", sans-serif;
  --display: "Outfit", sans-serif;
  --sidebar-w: 248px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

[hidden] { display: none !important; }

.brand {
  font-family: var(--display);
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--accent);
}

.muted { color: var(--muted); }
.error { color: var(--danger); margin: 0; }

.btn {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 10px;
  padding: 0.7rem 1rem;
  font: inherit;
  cursor: pointer;
  min-height: 44px;
  touch-action: manipulation;
}
.btn.primary {
  background: linear-gradient(135deg, var(--accent), #c9860d);
  border-color: transparent;
  color: #1a1205;
  font-weight: 600;
}
.btn.ghost { background: transparent; }
.btn.danger { background: var(--danger); border-color: transparent; color: #fff; }
.btn.ok { background: var(--ok); border-color: transparent; color: #06251e; font-weight: 600; }
.btn-block { width: 100%; }
.btn-sm { min-height: 38px; padding: 0.45rem 0.75rem; font-size: 0.88rem; }

.icon-btn {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 10px;
  width: 44px;
  height: 44px;
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  touch-action: manipulation;
}

input, select, textarea {
  width: 100%;
  background: #121820;
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  padding: 0.75rem 0.85rem;
  font: inherit;
  min-height: 44px;
}
textarea { min-height: 96px; resize: vertical; }
label { display: grid; gap: 0.35rem; font-size: 0.9rem; color: var(--muted); }

/* Login */
.login-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
  padding: 1rem;
  padding-top: calc(1rem + var(--safe-t));
  padding-bottom: calc(1rem + var(--safe-b));
}
.login-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 15% 20%, rgba(232, 163, 23, 0.18), transparent 55%),
    radial-gradient(ellipse 70% 50% at 85% 80%, rgba(60, 184, 154, 0.12), transparent 50%),
    linear-gradient(160deg, #0b1016, #16202b 55%, #0f1419);
}
.login-card {
  position: relative;
  width: min(420px, 100%);
  background: rgba(28, 37, 48, 0.92);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: clamp(1.25rem, 4vw, 2rem);
  display: grid;
  gap: 0.85rem;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}
.login-card h1 {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(1.35rem, 4vw, 1.6rem);
}
.login-card .brand { font-size: 1.4rem; margin: 0; }

/* App shell */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
  min-height: 100dvh;
}
.sidebar {
  background:
    linear-gradient(180deg, rgba(232, 163, 23, 0.06), transparent 30%),
    var(--bg-2);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 1.25rem 0.9rem;
  gap: 1rem;
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  overflow: auto;
}
.sidebar-brand {
  padding: 0.4rem 0.6rem 1rem;
  position: relative;
}
.sidebar-brand .brand { font-size: 1.5rem; display: block; }
.sidebar-brand small { color: var(--muted); display: block; line-height: 1.35; }
.sidebar-close { display: none; position: absolute; top: 0; right: 0; font-size: 1.4rem; }
.sidebar nav { display: grid; gap: 0.35rem; flex: 1; }
.nav-btn {
  text-align: left;
  background: transparent;
  border: 0;
  color: var(--muted);
  padding: 0.8rem 0.85rem;
  border-radius: 10px;
  font: inherit;
  cursor: pointer;
  min-height: 44px;
  touch-action: manipulation;
}
.nav-btn:hover { background: rgba(255,255,255,0.04); color: var(--text); }
.nav-btn.active {
  background: rgba(232, 163, 23, 0.14);
  color: var(--accent-2);
  font-weight: 600;
}
.sidebar-foot {
  display: grid;
  gap: 0.5rem;
  padding: 0.6rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.85rem;
}
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 12, 0.55);
  z-index: 40;
}
.app.sidebar-open .sidebar-backdrop {
  display: block;
}

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.85rem;
  padding: 0.9rem 1.25rem;
  padding-top: calc(0.9rem + var(--safe-t));
  border-bottom: 1px solid var(--line);
  background: rgba(15, 20, 25, 0.9);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}
.menu-toggle { display: none; }
.menu-toggle span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  margin: 2px 0;
}
.topbar h2 {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(1.1rem, 3vw, 1.35rem);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-actions { width: min(360px, 100%); flex: 1; max-width: 360px; }
.content {
  padding: 1.1rem 1.25rem calc(1.5rem + var(--safe-b));
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(148px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.25rem;
}
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.05rem;
}
.card .label { color: var(--muted); font-size: 0.85rem; }
.card .value {
  font-family: var(--display);
  font-size: clamp(1.15rem, 3.5vw, 1.55rem);
  margin-top: 0.35rem;
  word-break: break-word;
}
.card.danger .value { color: var(--danger); }
.card.ok .value { color: var(--ok); }
.card.warn .value { color: var(--accent); }

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  -webkit-overflow-scrolling: touch;
}
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { padding: 0.75rem 0.9rem; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-weight: 500; background: rgba(0,0,0,0.15); position: sticky; top: 0; }
tr:hover td { background: rgba(255,255,255,0.03); }
tr.clickable { cursor: pointer; }

/* Mobile card-list (tables dönüşümü) */
.job-cards { display: none; gap: 0.75rem; }
.job-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.95rem 1rem;
  cursor: pointer;
  display: grid;
  gap: 0.45rem;
}
.job-card:active { background: #222c38; }
.job-card-top {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: flex-start;
}
.job-card-title {
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.02rem;
}
.job-card-meta {
  display: grid;
  gap: 0.25rem;
  color: var(--muted);
  font-size: 0.88rem;
}
.job-card-row {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  font-size: 0.9rem;
}
.job-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.35rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge.red { background: rgba(232, 93, 76, 0.18); color: #ffb0a6; }
.badge.green { background: rgba(60, 184, 154, 0.18); color: #8fe3cf; }
.badge.amber { background: rgba(232, 163, 23, 0.18); color: #f0c14d; }
.badge.gray { background: rgba(143, 160, 179, 0.15); color: var(--muted); }

.toolbar {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 0.9rem;
  align-items: end;
}
.toolbar label { min-width: min(100%, 140px); flex: 1 1 140px; }
.toolbar .btn { flex: 0 0 auto; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem;
}
.panel-block {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}

dialog {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--bg-2);
  color: var(--text);
  width: min(760px, calc(100% - 1.25rem));
  max-width: 100%;
  padding: 0;
  box-shadow: var(--shadow);
  margin: auto;
}
dialog::backdrop { background: rgba(5, 8, 12, 0.72); }
.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--line);
  margin: 0;
}
.dialog-head h3 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.05rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#dialog-body { padding: 1rem; max-height: min(70vh, 70dvh); overflow: auto; }

.empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--muted);
}

/* Tablet */
@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: min(var(--sidebar-w), 86vw);
    z-index: 50;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    border-right: 1px solid var(--line);
    height: 100vh;
    height: 100dvh;
  }
  .app.sidebar-open .sidebar { transform: translateX(0); }
  .sidebar-close { display: inline-grid; }
  .menu-toggle { display: inline-grid; }
  .topbar {
    flex-wrap: wrap;
    padding-left: 0.85rem;
    padding-right: 0.85rem;
  }
  .topbar-actions {
    flex: 1 1 100%;
    max-width: none;
    order: 3;
  }
  .content { padding-left: 0.85rem; padding-right: 0.85rem; }
}

/* Phone */
@media (max-width: 640px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card .value { font-size: 1.15rem; }

  .desktop-only { display: none !important; }
  .table-wrap.table-as-cards {
    border: 0;
    background: transparent;
    overflow: visible;
  }
  .table-wrap.table-as-cards table { display: none; }
  .job-cards { display: grid; }

  .toolbar label { flex: 1 1 100%; min-width: 0; }
  .toolbar .btn { width: 100%; }
  .form-grid { grid-template-columns: 1fr; }

  dialog {
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
    border: 0;
  }
  #dialog-body { max-height: calc(100dvh - 64px); }

  .job-card-actions .btn { flex: 1 1 auto; }
}

@media (max-width: 380px) {
  .cards { grid-template-columns: 1fr; }
}
