:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1b1f24;
  --muted: #667085;
  --border: #e4e7eb;
  --border-strong: #d3d8de;
  --accent: #2563eb;
  --up: #15803d;
  --up-bg: #dcfce7;
  --down: #b91c1c;
  --down-bg: #fee2e2;
  --idle: #5b6472;
  --idle-bg: #eef0f3;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .04);
  --shadow-hover: 0 4px 14px rgba(16, 24, 40, .08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1115;
    --surface: #161a20;
    --text: #e6e8eb;
    --muted: #98a1ad;
    --border: #252b33;
    --border-strong: #343b45;
    --accent: #60a5fa;
    --up: #4ade80;
    --up-bg: rgba(74, 222, 128, .12);
    --down: #f87171;
    --down-bg: rgba(248, 113, 113, .12);
    --idle: #a3acb8;
    --idle-bg: #222831;
    --shadow: none;
    --shadow-hover: 0 4px 14px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.wrap { width: 100%; max-width: 1280px; margin: 0 auto; padding: 0 16px; }
code { font-size: 12px; background: var(--border); padding: 1px 5px; border-radius: 4px; }
button { font: inherit; }

/* ---------- Üst şerit ---------- */
.top { background: var(--surface); border-bottom: 1px solid var(--border); }
.top .wrap { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 68px; }
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; color: inherit; text-decoration: none; }
.logo { display: flex; flex-shrink: 0; padding-right: 14px; border-right: 1px solid var(--border); }
.logo img { height: 40px; width: auto; display: block; }
.brand-text { min-width: 0; }
h1 { font-size: 18px; line-height: 1.25; margin: 0; }
.brand p { margin: 0; font-size: 12px; color: var(--muted); }

.ghost {
  display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0;
  border: 1px solid var(--border); background: transparent; color: var(--text);
  padding: 7px 12px; border-radius: 8px; cursor: pointer; font-size: 13px;
}
.ghost:hover { border-color: var(--accent); color: var(--accent); }

main.wrap { padding-top: 20px; padding-bottom: 16px; }

/* ---------- Uygulama kartları: tek tip, eşit ızgara ---------- */
/* Tüm kategoriler aynı sütunları paylaşır (subgrid): başlıklar ve kartlar her genişlikte hizalı.
   Her kategori kart sayısı kadar sütun kaplar; küçük kategoriler yan yana dizilir. */
#apps { display: grid; grid-template-columns: minmax(0, 1fr); gap: 22px 14px; }
@media (min-width: 561px) { #apps { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 820px) { #apps { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1100px) { #apps { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

.group { display: grid; grid-template-columns: subgrid; row-gap: 14px; align-content: start; min-width: 0; }
.group-title {
  grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; margin: 0;
  font-size: 13px; font-weight: 600; color: var(--text);
}
.group-title::before { content: ""; width: 10px; height: 10px; border-radius: 3px; background: var(--c, var(--muted)); }
.group-title .n { font-size: 11px; font-weight: 500; color: var(--muted); background: var(--idle-bg); border-radius: 999px; padding: 1px 8px; }
.group-title::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.tile {
  position: relative; display: flex; flex-direction: column; gap: 10px; min-width: 0;
  padding: 16px; border-radius: 12px; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  color: inherit; text-decoration: none;
  transition: box-shadow .15s, border-color .15s, transform .15s;
}
.tile::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 3px; background: var(--c, var(--border)); }
a.tile:hover { border-color: var(--border-strong); box-shadow: var(--shadow-hover); transform: translateY(-1px); }
a.tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.tile-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.tile-logo {
  width: 44px; height: 44px; border-radius: 10px; background: var(--bg); flex-shrink: 0;
  display: grid; place-items: center; overflow: hidden; font-size: 22px;
}
.tile-logo img { width: 36px; height: 36px; object-fit: contain; display: block; }

.tile-name { margin: 0; font-size: 15px; font-weight: 600; line-height: 1.3; }
.tile-desc {
  margin: -4px 0 0; font-size: 13px; line-height: 1.4; color: var(--muted);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  min-height: 2.8em;
}

.tile-foot {
  margin-top: auto; padding-top: 10px; border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px;
}
.cat { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cat::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--c, var(--muted)); flex-shrink: 0; }
.actions { display: inline-flex; align-items: center; gap: 12px; flex-shrink: 0; }
.repo { color: var(--muted); cursor: pointer; }
.repo:hover { color: var(--accent); text-decoration: underline; }
.open { color: var(--accent); font-weight: 600; }
.soon { color: var(--muted); }

.pill {
  display: inline-flex; align-items: center; gap: 5px; white-space: nowrap;
  font-size: 11px; font-weight: 500; padding: 3px 8px; border-radius: 999px;
  color: var(--idle); background: var(--idle-bg);
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.up { color: var(--up); background: var(--up-bg); }
.pill.down { color: var(--down); background: var(--down-bg); }

.empty { color: var(--muted); }

footer.wrap { color: var(--muted); font-size: 12px; padding-bottom: 16px; }

/* ---------- Kullanıcı şeridi ---------- */
.top-actions { display: flex; align-items: center; gap: 14px; flex-shrink: 0; }
.userbar { display: flex; align-items: center; gap: 12px; font-size: 13px; }
.userbar:empty { display: none; }
.who { font-weight: 600; max-width: 180px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.usernav { display: flex; align-items: center; gap: 12px; }
.usernav a, .linkbtn { color: var(--muted); text-decoration: none; background: none; border: 0; padding: 0; cursor: pointer; font-size: 13px; }
.usernav a:hover, .linkbtn:hover { color: var(--accent); }
.usernav form { display: inline; margin: 0; }

/* ---------- Formlar ---------- */
.form { display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 500; }
input[type="email"], input[type="password"], input[type="text"], select {
  height: 40px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--bg); color: var(--text); font: inherit; font-size: 14px;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
button { font: inherit; }
.primary {
  height: 40px; border: 0; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 14px;
  background: #c8102e; color: #fff;
}
.primary:hover { filter: brightness(1.08); }
.danger { border: 1px solid var(--down); color: var(--down); background: transparent; border-radius: 6px; padding: 4px 10px; cursor: pointer; font-size: 12px; }
.alert { margin: 0; padding: 10px 12px; border-radius: 8px; font-size: 13px; }
.alert.error { color: var(--down); background: var(--down-bg); }
.alert.ok { color: var(--up); background: var(--up-bg); }
.hint, .muted { margin: 0; font-size: 12px; color: var(--muted); }

/* ---------- Giriş sayfası ---------- */
.auth-body { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth { width: 100%; max-width: 380px; }
.auth-card {
  display: flex; flex-direction: column; gap: 14px; padding: 28px 24px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-hover);
}
.auth-logo { display: flex; justify-content: center; }
.auth-logo img { height: 56px; width: auto; }
.auth-card h1 { margin: 4px 0 0; text-align: center; font-size: 20px; }
.auth-card > .muted { text-align: center; }

/* ---------- Yönetim sayfaları ---------- */
.panel-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
  padding: 18px; margin-bottom: 16px; display: flex; flex-direction: column; gap: 14px; overflow-x: auto;
}
.panel-card.narrow { max-width: 460px; }
.panel-card h2 { margin: 0; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.panel-card h2 .n { font-size: 11px; font-weight: 500; color: var(--muted); background: var(--idle-bg); border-radius: 999px; padding: 1px 8px; }
table.users { width: 100%; border-collapse: collapse; font-size: 13px; }
table.users th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 8px; border-bottom: 1px solid var(--border); }
table.users td { padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.actions-cell { display: flex; gap: 10px; align-items: flex-start; justify-content: flex-end; flex-wrap: wrap; }
.actions-cell form { margin: 0; }
.actions-cell summary { cursor: pointer; color: var(--accent); font-size: 12px; list-style: none; }
.inline-form { display: flex; gap: 6px; margin-top: 6px; }
.inline-form input { height: 32px; font-size: 13px; }
.inline-form button { height: 32px; border-radius: 6px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); cursor: pointer; padding: 0 10px; }

/* ---------- Telefon ---------- */
@media (max-width: 560px) {
  .top .wrap { min-height: 58px; }
  .logo { padding-right: 10px; }
  .logo img { height: 30px; }
  .brand { gap: 10px; }
  h1 { font-size: 15px; }
  .brand p { display: none; }
  .ghost .label { display: none; }
  .ghost { padding: 7px 10px; }
  main.wrap { padding-top: 14px; }
  #apps { row-gap: 18px; }
  .group { row-gap: 10px; }

  /* Kart yatay: logo solda, ad + açıklama sağda, durum sağ üstte */
  .tile {
    display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; column-gap: 12px; row-gap: 2px;
    grid-template-areas: "logo name pill" "logo desc desc" "foot foot foot";
    padding: 12px 14px;
  }
  .tile-top { display: contents; }
  .tile-logo { grid-area: logo; width: 40px; height: 40px; align-self: start; }
  .tile-logo img { width: 32px; height: 32px; }
  .tile .pill { grid-area: pill; align-self: start; }
  .tile-name { grid-area: name; align-self: center; font-size: 14px; }
  .tile-desc { grid-area: desc; margin: 0; min-height: 0; font-size: 12px; }
  .tile-foot { grid-area: foot; margin-top: 8px; padding-top: 8px; }

  .who { display: none; }
  .top-actions { gap: 10px; }
  /* Menü başlığın yanına sığmazsa ikinci satıra iner */
  .top .wrap { flex-wrap: wrap; row-gap: 4px; padding-top: 8px; padding-bottom: 8px; }
  .top .wrap > .userbar, .top-actions { margin-left: auto; }
  table.users thead { display: none; }
  table.users, table.users tbody, table.users tr, table.users td { display: block; width: 100%; }
  table.users tr { border-bottom: 1px solid var(--border); padding: 8px 0; }
  table.users td { border: 0; padding: 3px 0; }
  table.users td[data-l]::before { content: attr(data-l) ": "; color: var(--muted); }
  .actions-cell { justify-content: flex-start; }
}
