/* ==========================================================================
   Philips Kanal Sıralama Editörü
   Claude'un sıcak kum/mercan paletinden esinlenilmiş arayüz.
   ========================================================================== */

:root {
  /* Açık tema — varsayılan */
  --bg:          #F4F2EC;
  --surface:     #FFFFFF;
  --raised:      #FAF9F5;
  --sunken:      #EFEDE5;

  --line:        #E2DED4;
  --line-soft:   #EDEAE2;
  --line-strong: #D3CEC1;

  --fg:          #1F1E1D;
  --fg-dim:      #6B6760;
  --fg-faint:    #97928A;

  --accent:      #D97757;
  --accent-hi:   #C7623F;
  --accent-soft: #FAEBE4;
  --accent-line: #EFC9B8;
  --accent-fg:   #FFFFFF;

  --ok:          #3F7D58;
  --ok-soft:     #E6F0E9;
  --ok-line:     #BEDAC8;

  --warn:        #A9761C;
  --warn-soft:   #FBF0DC;
  --warn-line:   #E8D3A6;

  --danger:      #B4483A;
  --danger-soft: #FBE9E6;
  --danger-line: #EFC4BC;

  --violet:      #7A5AA8;
  --violet-soft: #F0EBF7;
  --violet-line: #D8CBEB;

  --shadow-sm: 0 1px 2px rgba(31,30,29,.06);
  --shadow-md: 0 4px 14px rgba(31,30,29,.10);
  --shadow-lg: 0 16px 44px rgba(31,30,29,.18);

  --radius:    9px;
  --radius-sm: 6px;
  --row-h:     36px;

  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Mono", Consolas, monospace;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:          #1B1A18;
    --surface:     #232220;
    --raised:      #2A2825;
    --sunken:      #161514;

    --line:        #393733;
    --line-soft:   #2E2C29;
    --line-strong: #4A4741;

    --fg:          #F0EEE6;
    --fg-dim:      #A6A199;
    --fg-faint:    #78736B;

    --accent:      #E0895F;
    --accent-hi:   #EDA07A;
    --accent-soft: #3A2A22;
    --accent-line: #6B4632;

    --ok:          #7FBF95;
    --ok-soft:     #1F2C24;
    --ok-line:     #38513F;

    --warn:        #DCAE5E;
    --warn-soft:   #2F2718;
    --warn-line:   #574B2C;

    --danger:      #E58575;
    --danger-soft: #331F1C;
    --danger-line: #5E3730;

    --violet:      #B49BDD;
    --violet-soft: #272132;
    --violet-line: #453A5C;

    --shadow-sm: 0 1px 2px rgba(0,0,0,.35);
    --shadow-md: 0 4px 14px rgba(0,0,0,.45);
    --shadow-lg: 0 16px 44px rgba(0,0,0,.6);
  }
}

:root[data-theme="dark"] {
  --bg:          #1B1A18;
  --surface:     #232220;
  --raised:      #2A2825;
  --sunken:      #161514;

  --line:        #393733;
  --line-soft:   #2E2C29;
  --line-strong: #4A4741;

  --fg:          #F0EEE6;
  --fg-dim:      #A6A199;
  --fg-faint:    #78736B;

  --accent:      #E0895F;
  --accent-hi:   #EDA07A;
  --accent-soft: #3A2A22;
  --accent-line: #6B4632;

  --ok:          #7FBF95;
  --ok-soft:     #1F2C24;
  --ok-line:     #38513F;

  --warn:        #DCAE5E;
  --warn-soft:   #2F2718;
  --warn-line:   #574B2C;

  --danger:      #E58575;
  --danger-soft: #331F1C;
  --danger-line: #5E3730;

  --violet:      #B49BDD;
  --violet-soft: #272132;
  --violet-line: #453A5C;

  --shadow-sm: 0 1px 2px rgba(0,0,0,.35);
  --shadow-md: 0 4px 14px rgba(0,0,0,.45);
  --shadow-lg: 0 16px 44px rgba(0,0,0,.6);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }

/* .welcome/.toolbar/.inspector gibi kurallar display tanımladığı için tarayıcının
   varsayılan [hidden] kuralını ezerdi — bunu açıkça geri alıyoruz. */
[hidden] { display: none !important; }

body {
  background: var(--bg);
  color: var(--fg);
  font: 13.5px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button, input, select, textarea { font: inherit; color: inherit; }

::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 8px; border: 3px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--fg-faint); }

/* ========================================================================== */
/* İskelet                                                                    */
/* ========================================================================== */

#app { display: grid; grid-template-rows: auto auto auto 1fr auto; height: 100vh; }

/* --- Bul & taşı şeridi ---------------------------------------------------- */

.findbar {
  display: flex; align-items: center; gap: 9px; flex-wrap: wrap;
  padding: 8px 16px;
  background: var(--accent-soft);
  border-bottom: 1px solid var(--accent-line);
  font-size: 12.5px; color: var(--accent-hi);
  flex-shrink: 0;
}
.findbar b { color: var(--fg); font-weight: 650; }
.findbar .btn { background: var(--surface); border-color: var(--accent-line); }
.findbar .btn:hover:not(:disabled) { background: var(--surface); border-color: var(--accent); color: var(--accent-hi); }
.findbar input[type="number"] { width: 74px; border-color: var(--accent-line); }
.findbar .field { color: var(--accent-hi); }

/* Satır içi hızlı taşıma düğmeleri */
.rowbtn {
  border: 0; background: none; cursor: pointer;
  color: var(--fg-faint); font-size: 14px; line-height: 1;
  padding: 3px 5px; border-radius: 4px; opacity: .3;
  transition: opacity .12s, background .12s, color .12s;
}
tr:hover .rowbtn, .rowbtn:focus-visible { opacity: 1; }
.rowbtn:hover { background: var(--accent-soft); color: var(--accent); }

/* --- Üst çubuk ------------------------------------------------------------ */

.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 0 16px; height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.brand { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.brand .mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--accent);
  display: grid; place-items: center;
  color: #fff; flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}
.brand .txt { line-height: 1.25; }
.brand .txt b { font-weight: 650; letter-spacing: -0.012em; font-size: 14px; }
.brand .txt small { display: block; font-size: 11px; color: var(--fg-faint); }

.topbar-meta { display: flex; gap: 6px; align-items: center; min-width: 0; overflow: hidden; }
.spacer { flex: 1 1 auto; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 100px;
  background: var(--sunken); border: 1px solid var(--line);
  font-size: 11.5px; color: var(--fg-dim); white-space: nowrap;
}
.badge b { color: var(--fg); font-weight: 600; }
.badge .src-pick { cursor: pointer; padding: 0 2px; border-radius: 3px; }
.badge .src-pick.on { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }

/* --- Butonlar ------------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 6px 12px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  color: var(--fg); cursor: pointer; white-space: nowrap;
  transition: background .13s, border-color .13s, color .13s;
  user-select: none;
}
.btn:hover:not(:disabled) { background: var(--sunken); border-color: var(--fg-faint); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn.primary {
  background: var(--accent); border-color: var(--accent);
  color: var(--accent-fg); font-weight: 550;
  box-shadow: var(--shadow-sm);
}
.btn.primary:hover:not(:disabled) { background: var(--accent-hi); border-color: var(--accent-hi); }

.btn.ghost { background: transparent; border-color: transparent; color: var(--fg-dim); }
.btn.ghost:hover:not(:disabled) { background: var(--sunken); color: var(--fg); }
.btn.icon { padding: 6px 9px; }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }
.btn.danger { color: var(--danger); border-color: var(--danger-line); }
.btn.danger:hover:not(:disabled) { background: var(--danger-soft); }

.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); margin-left: 0; }
.btn-group .btn:last-child  { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }

/* --- Sekmeler ------------------------------------------------------------- */

.tabs { display: inline-flex; gap: 2px; background: var(--sunken); padding: 3px; border-radius: 8px; }
.tab {
  padding: 5px 14px; border: 0; background: transparent;
  border-radius: 6px; cursor: pointer; color: var(--fg-dim);
  font-size: 13px; font-weight: 500; transition: background .13s, color .13s;
}
.tab:hover { color: var(--fg); }
.tab.on { background: var(--surface); color: var(--fg); font-weight: 600; box-shadow: var(--shadow-sm); }
.tab .cnt {
  display: inline-block; margin-left: 6px; padding: 0 6px;
  border-radius: 100px; background: var(--accent-soft);
  color: var(--accent); font-size: 11px; font-weight: 650;
}

/* --- Araç çubuğu ---------------------------------------------------------- */

.toolbar {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 16px;
  background: var(--raised);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap; flex-shrink: 0;
}
.tool-sep { width: 1px; align-self: stretch; background: var(--line); margin: 0 3px; }
.field { display: inline-flex; align-items: center; gap: 6px; color: var(--fg-dim); font-size: 12.5px; }

input[type="text"], input[type="number"], input[type="search"], select {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 6px 10px; color: var(--fg); outline: none;
  transition: border-color .13s, box-shadow .13s;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input::placeholder { color: var(--fg-faint); }

.search-wrap { position: relative; }
.search-wrap input { padding-left: 32px; width: 240px; }
.search-wrap svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--fg-faint); pointer-events: none; }

.chips { display: inline-flex; }
.chip {
  padding: 5px 11px; background: var(--surface);
  border: 1px solid var(--line-strong); color: var(--fg-dim);
  cursor: pointer; margin-left: -1px; font-size: 12.5px;
  transition: background .13s, color .13s;
}
.chip:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); margin-left: 0; }
.chip:last-child  { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.chip:hover { background: var(--sunken); color: var(--fg); }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-hi); font-weight: 550; z-index: 1; position: relative; }

/* --- Ana alan ------------------------------------------------------------- */

.main { display: grid; grid-template-columns: 1fr 300px; min-height: 0; overflow: hidden; }

.table-wrap { overflow: auto; min-height: 0; background: var(--bg); }

table.channels { width: 100%; border-collapse: separate; border-spacing: 0; table-layout: fixed; }

table.channels thead th {
  position: sticky; top: 0; z-index: 3;
  background: var(--raised);
  border-bottom: 1px solid var(--line);
  padding: 8px; text-align: left;
  font-size: 11px; font-weight: 650; letter-spacing: .05em; text-transform: uppercase;
  color: var(--fg-faint); white-space: nowrap; user-select: none;
}

table.channels td {
  padding: 0 8px; height: var(--row-h);
  border-bottom: 1px solid var(--line-soft);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle;
}

tbody tr { background: var(--surface); transition: background .1s; }
tbody tr:nth-child(even) { background: var(--raised); }
tbody tr:hover { background: var(--sunken); }
tbody tr.selected { background: var(--accent-soft); }
tbody tr.selected td { border-bottom-color: var(--accent-line); }
tbody tr.moved td.c-new { color: var(--accent-hi); font-weight: 650; }
tbody tr.hidden-ch td.c-name { color: var(--fg-faint); text-decoration: line-through; }
tbody tr.renamed td.c-name { color: var(--accent-hi); }

.c-grip  { width: 28px; text-align: center; color: var(--fg-faint); cursor: grab; }
.c-grip:active { cursor: grabbing; }
.c-sel   { width: 32px; text-align: center; }
.c-fav   { width: 42px; text-align: center; }
.c-new   { width: 68px; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.c-old   { width: 58px; font-family: var(--mono); color: var(--fg-faint); font-variant-numeric: tabular-nums; font-size: 12px; }
.c-name  { width: auto; min-width: 150px; font-weight: 500; }
.c-flags { width: 100px; }
.c-freq  { width: 100px; font-family: var(--mono); color: var(--fg-dim); font-size: 12px; }
.c-sid   { width: 112px; font-family: var(--mono); color: var(--fg-faint); font-size: 12px; }
.c-act   { width: 44px; text-align: center; }

.numbox {
  width: 58px; padding: 3px 6px;
  background: transparent; border: 1px solid transparent; border-radius: 5px;
  font-family: var(--mono); font-variant-numeric: tabular-nums;
  text-align: right; color: inherit; font-weight: inherit;
}
.numbox:hover { border-color: var(--line-strong); background: var(--surface); }
.numbox:focus { border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px var(--accent-soft); }
.numbox::-webkit-outer-spin-button, .numbox::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* Favori yıldızı */
.star {
  border: 0; background: none; cursor: pointer; padding: 2px 4px;
  font-size: 16px; line-height: 1; color: var(--line-strong);
  transition: color .13s, transform .13s;
}
.star:hover { color: var(--accent); transform: scale(1.18); }
.star.on { color: var(--accent); }
.fav-marks {
  display: block; font-family: var(--mono); font-size: 9px;
  color: var(--accent); letter-spacing: .5px; margin-top: -3px; height: 10px;
}

.tag {
  display: inline-block; padding: 1px 6px; border-radius: 4px;
  font-size: 10px; font-weight: 650; letter-spacing: .03em;
  border: 1px solid; margin-right: 3px;
}
.tag.hd    { color: var(--ok);     border-color: var(--ok-line);     background: var(--ok-soft); }
.tag.radio { color: var(--violet); border-color: var(--violet-line); background: var(--violet-soft); }
.tag.scr   { color: var(--warn);   border-color: var(--warn-line);   background: var(--warn-soft); }
.tag.hide  { color: var(--danger); border-color: var(--danger-line); background: var(--danger-soft); }

input[type="checkbox"] { accent-color: var(--accent); cursor: pointer; margin: 0; width: 15px; height: 15px; }

.sortable-ghost { opacity: .3; }
.sortable-chosen { background: var(--accent-soft) !important; }
.sortable-drag { background: var(--surface) !important; box-shadow: var(--shadow-lg); }

/* --- Sağ panel ------------------------------------------------------------ */

.inspector {
  border-left: 1px solid var(--line);
  background: var(--raised);
  overflow-y: auto; padding: 16px;
  display: flex; flex-direction: column; gap: 18px; min-height: 0;
}
.insp-section h3 {
  margin: 0 0 9px; font-size: 11px; font-weight: 650;
  letter-spacing: .06em; text-transform: uppercase; color: var(--fg-faint);
}

.kv { display: grid; grid-template-columns: 92px 1fr; gap: 5px 8px; font-size: 12px; }
.kv dt { color: var(--fg-faint); }
.kv dd { margin: 0; font-family: var(--mono); word-break: break-all; }

.stack { display: flex; flex-direction: column; gap: 8px; }

.hint { font-size: 11.5px; color: var(--fg-dim); line-height: 1.6; }
.hint code {
  font-family: var(--mono); background: var(--sunken);
  padding: 1px 4px; border-radius: 3px; font-size: 11px; color: var(--fg-dim);
}
.hint b { color: var(--fg); }

.issues { display: flex; flex-direction: column; gap: 6px; }
.issue {
  display: flex; gap: 7px; padding: 8px 10px; border-radius: var(--radius-sm);
  font-size: 11.5px; line-height: 1.5; border: 1px solid;
}
.issue.error { background: var(--danger-soft); border-color: var(--danger-line); color: var(--danger); }
.issue.warn  { background: var(--warn-soft);   border-color: var(--warn-line);   color: var(--warn); }
.issue.ok    { background: var(--ok-soft);     border-color: var(--ok-line);     color: var(--ok); }

.diff-list {
  max-height: 200px; overflow-y: auto;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface);
}
.diff-row {
  display: grid; grid-template-columns: 1fr auto; gap: 8px;
  padding: 4px 9px; font-size: 11.5px; border-bottom: 1px solid var(--line-soft);
}
.diff-row:last-child { border-bottom: 0; }
.diff-row span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.diff-row span:last-child { font-family: var(--mono); color: var(--accent-hi); white-space: nowrap; }

/* Favori liste seçici (sağ panel) */
.fav-picker { display: flex; flex-direction: column; gap: 4px; }
.fav-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface);
  cursor: pointer; font-size: 12.5px; transition: background .13s, border-color .13s;
}
.fav-item:hover { background: var(--sunken); }
.fav-item.on { border-color: var(--accent); background: var(--accent-soft); }
.fav-item .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.fav-item .ct {
  font-family: var(--mono); font-size: 11px; color: var(--fg-faint);
  background: var(--sunken); border-radius: 100px; padding: 1px 7px;
}
.fav-item.on .ct { background: var(--surface); color: var(--accent); }

/* --- Durum çubuğu --------------------------------------------------------- */

.statusbar {
  display: flex; align-items: center; gap: 16px;
  padding: 0 16px; height: 32px;
  background: var(--surface); border-top: 1px solid var(--line);
  font-size: 11.5px; color: var(--fg-dim); flex-shrink: 0;
}
.statusbar b { color: var(--fg); font-weight: 650; font-variant-numeric: tabular-nums; }

/* --- Karşılama ------------------------------------------------------------ */

.welcome { grid-column: 1 / -1; display: flex; align-items: center; justify-content: center; padding: 32px; overflow-y: auto; }
.welcome-card { max-width: 660px; width: 100%; text-align: center; }

.dropzone {
  border: 2px dashed var(--line-strong); border-radius: 14px;
  padding: 46px 34px; background: var(--surface);
  transition: border-color .16s, background .16s;
}
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone h2 { margin: 16px 0 8px; font-size: 21px; font-weight: 650; letter-spacing: -0.015em; }
.dropzone p { margin: 0 0 22px; color: var(--fg-dim); font-size: 13.5px; line-height: 1.65; }
.dropzone .actions { display: flex; gap: 9px; justify-content: center; flex-wrap: wrap; }

.welcome-note {
  margin-top: 22px; text-align: left; font-size: 12.5px;
  color: var(--fg-dim); line-height: 1.7;
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; background: var(--surface);
}
.welcome-note strong { color: var(--fg); }
.welcome-note code { font-family: var(--mono); font-size: 11.5px; background: var(--sunken); padding: 1px 4px; border-radius: 3px; }
.welcome-note ul { margin: 8px 0 0; padding-left: 18px; }
.welcome-note li { margin: 4px 0; }

/* --- Modal ---------------------------------------------------------------- */

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(31,30,29,.42);
  backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 24px;
}
.modal {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; width: 100%; max-width: 580px; max-height: 86vh;
  display: flex; flex-direction: column; box-shadow: var(--shadow-lg);
}
.modal header {
  padding: 15px 20px; border-bottom: 1px solid var(--line);
  font-weight: 650; display: flex; align-items: center; justify-content: space-between;
}
.modal .body { padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.modal footer { padding: 13px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

/* --- Bildirim ------------------------------------------------------------- */

#toasts { position: fixed; bottom: 46px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 200; pointer-events: none; }
.toast {
  pointer-events: auto; background: var(--surface);
  border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm); padding: 11px 15px;
  font-size: 12.5px; max-width: 390px; box-shadow: var(--shadow-md);
  animation: slidein .2s cubic-bezier(.2,.8,.3,1);
}
.toast.ok    { border-left-color: var(--ok); }
.toast.warn  { border-left-color: var(--warn); }
.toast.error { border-left-color: var(--danger); }
.toast b { display: block; margin-bottom: 2px; }
.toast span { color: var(--fg-dim); }

@keyframes slidein { from { opacity: 0; transform: translateX(18px); } to { opacity: 1; transform: none; } }

kbd {
  font-family: var(--mono); font-size: 10.5px; padding: 1px 5px;
  border: 1px solid var(--line-strong); border-bottom-width: 2px;
  border-radius: 4px; background: var(--sunken); color: var(--fg-dim);
}

@media (max-width: 1180px) {
  .main { grid-template-columns: 1fr; }
  .inspector { display: none; }
  .c-sid { display: none; }
}
@media (max-width: 820px) {
  .c-freq, .c-old { display: none; }
  .search-wrap input { width: 150px; }
}
