/* Iskreni admin panel — minimal, dependency-free styling */
:root {
    --brand: #EF4923;
    --brand-dark: #DF2B26;
    --error: #C52426;
    --bg: #F8F8F8;
    --surface: #FFFFFF;
    --border: #E8E8E8;
    --text: #1D1D1D;
    --muted: #999999;
    --sidebar-w: 240px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.5;
}

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

h1, h2, h3 { color: var(--text); font-weight: 600; margin: 0 0 16px; }
h1 { font-size: 24px; }
h2 { font-size: 18px; margin-top: 32px; }
h3 { font-size: 15px; }

/* ───────────── Layout ───────────── */
.sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-w);
    background: #FFFFFF;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 24px 16px;
}
.brand {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 0 8px 24px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
    text-decoration: none;
}
.brand:hover { text-decoration: none; }
.brand img {
    height: 22px;
    width: auto;
    display: block;
}
.brand small { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }

.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar nav a {
    display: block;
    padding: 10px 12px;
    color: var(--text);
    border-radius: 8px;
    font-weight: 500;
}
.sidebar nav a:hover { background: var(--bg); text-decoration: none; }
.sidebar nav a.active {
    background: var(--brand);
    color: white;
}

.user {
    border-top: 1px solid var(--border);
    padding-top: 16px;
}
.user-name { font-weight: 600; font-size: 13px; }
.user-role { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; }
.user .link {
    background: none; border: none; padding: 0;
    color: var(--brand); cursor: pointer; font: inherit; font-size: 12px;
}
.user .link:hover { text-decoration: underline; }

main.with-sidebar {
    margin-left: var(--sidebar-w);
    padding: 32px 40px;
    /* Wide tables (Naslovi w/ landscape + portrait thumb columns) need room.
       Was 1100px and forms felt cramped; 1500 still keeps line lengths sane. */
    max-width: 1500px;
}
main.centered {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

/* ───────────── Cards / panels ───────────── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 16px;
}
.card-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
}
.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
}
.stat-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; }
.stat-value { font-size: 28px; font-weight: 700; margin-top: 4px; }
.stat-sub   { color: var(--muted); font-size: 12px; margin-top: 6px; line-height: 1.4; }

/* ───────────── Content-health grid ───────────── */
.health-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    margin-top: 16px;
}
.health-item {
    display: block;
    padding: 14px 16px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg);
    text-decoration: none;
    color: var(--text);
    transition: border-color 0.12s ease, transform 0.12s ease;
}
.health-item:hover { text-decoration: none; transform: translateY(-1px); border-color: var(--brand); }
.health-item .health-count { font-size: 22px; font-weight: 700; line-height: 1; }
.health-item .health-label { font-size: 12px; color: var(--muted); margin-top: 6px; }
.health-item.warn { border-color: rgba(239, 73, 35, 0.4); background: rgba(239, 73, 35, 0.05); }
.health-item.warn .health-count { color: var(--brand-dark); }
.health-item.ok .health-count   { color: var(--muted); }

/* ───────────── Forms ───────────── */
form .field {
    margin-bottom: 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
form label {
    font-weight: 500;
    font-size: 13px;
    color: var(--text);
}
form label .hint {
    color: var(--muted);
    font-weight: 400;
    font-size: 12px;
    margin-left: 6px;
}
form input[type="text"],
form input[type="email"],
form input[type="password"],
form input[type="number"],
form input[type="url"],
form input[type="datetime-local"],
form select,
form textarea {
    background: white;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    font-family: inherit;
    font-size: 14px;
    color: var(--text);
    width: 100%;
}
form textarea { min-height: 120px; resize: vertical; }
form input:focus, form select:focus, form textarea:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(239, 73, 35, 0.15);
}
form .checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 4px 0;
    font-weight: 500;
}
form .checkbox input { width: auto; }
form .actions {
    display: flex;
    gap: 8px;
    margin-top: 24px;
}

/* ───────────── Buttons ───────────── */
.btn {
    background: var(--brand);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 10px 18px;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    font-family: inherit;
}
.btn:hover { background: var(--brand-dark); text-decoration: none; color: white; }
.btn.secondary {
    background: white;
    color: var(--text);
    border: 1px solid var(--border);
}
.btn.secondary:hover { background: var(--bg); color: var(--text); }
.btn.danger { background: var(--error); }
.btn.danger:hover { background: #a01e1f; }
.btn.small { padding: 6px 12px; font-size: 12px; }

/* ───────────── Tables ───────────── */
.table-wrapper {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
}
table { width: 100%; border-collapse: collapse; }
th, td {
    text-align: left;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
th {
    background: var(--bg);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--muted);
    font-weight: 600;
}
tbody tr:hover { background: var(--bg); }
tbody tr:last-child td { border-bottom: none; }

.thumb {
    width: 100px; height: 56px;
    object-fit: cover; border-radius: 4px;
    background: var(--border);
}
/* Portrait variant for the Naslovi table — taller than wide. */
.thumb.portrait {
    width: 44px; height: 66px;
}
/* "Missing thumbnail" placeholder used to show at-a-glance which slot
   each title doesn't have art for yet. */
.thumb.missing {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px dashed var(--border);
    background: transparent;
    color: var(--muted);
    font-size: 18px;
    line-height: 1;
}

/* ───────────── Pagination + toolbar ───────────── */
.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.toolbar form { display: flex; gap: 8px; align-items: center; margin: 0; }
.toolbar form input[type="search"], .toolbar form input[type="text"] {
    background: white;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    font: inherit; font-size: 13px;
    min-width: 240px;
}
.pager {
    display: flex; gap: 4px; align-items: center;
    margin-top: 16px;
}
.pager a, .pager span {
    padding: 6px 10px;
    border-radius: 6px;
    color: var(--text);
    border: 1px solid var(--border);
    background: white;
    font-size: 13px;
}
.pager a:hover { background: var(--bg); text-decoration: none; }
.pager .current {
    background: var(--brand); color: white; border-color: var(--brand);
}
.pager .disabled { color: var(--muted); }

/* ───────────── Badges ───────────── */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 100px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.badge.green { background: #E6F4EA; color: #1E7F3E; }
.badge.gray { background: #EEEEEE; color: var(--muted); }
.badge.orange { background: #FDE7E1; color: var(--brand-dark); }
.badge.red { background: #FCE6E6; color: var(--error); }

/* ───────────── Messages ───────────── */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 13px;
}
.alert.success { background: #E6F4EA; color: #1E7F3E; border: 1px solid #C5E5D0; }
.alert.error { background: #FCE6E6; color: var(--error); border: 1px solid #F4C2C2; }
.alert.info { background: #E8F0FE; color: #1A56DB; border: 1px solid #C1D4FA; }

.field-error {
    color: var(--error);
    font-size: 12px;
    margin-top: 2px;
}

/* ───────────── File upload ───────────── */
.upload-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.upload-row {
    display: flex;
    flex-wrap: wrap;          /* URL input gets its own full-width line  */
    gap: 6px;
    align-items: center;
}
.upload-row > input[type="url"] {
    flex: 1 1 100%;           /* full width → buttons wrap to next line  */
    min-width: 0;
}
.upload-input {
    font-size: 12px;
    max-width: 200px;
}
.paste-btn {
    background: white;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 10px;
    font: inherit;
    font-size: 12px;
    color: var(--text);
    cursor: pointer;
}
.paste-btn:hover { background: var(--bg); }
.paste-btn:disabled { opacity: 0.5; cursor: default; }
.upload-input::file-selector-button {
    background: white;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 10px;
    font: inherit; font-size: 12px;
    cursor: pointer;
    margin-right: 6px;
}
.upload-input::file-selector-button:hover { background: var(--bg); }
.upload-status {
    font-size: 11px;
    color: var(--muted);
    min-height: 14px;
}
.upload-status.pending { color: var(--muted); }
.upload-status.success { color: #1E7F3E; }
.upload-status.error { color: var(--error); }

/* ───────────── Login screen ───────────── */
.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 40px;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.04);
}
.login-card h1 { text-align: center; margin-bottom: 8px; }
.login-card .sub { text-align: center; color: var(--muted); margin-bottom: 24px; font-size: 13px; }
.login-card .btn { width: 100%; padding: 12px; }
.login-logo {
    display: block;
    height: 40px;
    width: auto;
    margin: 0 auto 16px;
}

/* ─── Tom Select theming — match the panel's native input look ──────────── */
.ts-wrapper {
    width: 100%;
    /* Inside CSS grid `1fr` columns and flex containers, a wide selected option
       would otherwise push the wrapper past its allotted width. min-width:0
       lets the wrapper shrink; max-width:100% caps it at the parent's width. */
    min-width: 0;
    max-width: 100%;
}
.ts-wrapper .ts-control {
    background: white;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    font-family: inherit;
    font-size: 14px;
    color: var(--text);
    min-height: 40px;
    box-shadow: none;
    /* Prevent the inner flexbox from overflowing — combined with the .item
       truncation below this gives us ellipsis-clipped long titles. */
    overflow: hidden;
    flex-wrap: nowrap;
}
.ts-wrapper .ts-control > .item {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
    min-width: 0;
}
/* The dropdown menu can be wider than the control if we want — but cap it so
   it doesn't escape the viewport on long video titles. */
.ts-dropdown .option {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ts-wrapper.focus .ts-control {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(239, 73, 35, 0.15);
}
.ts-wrapper .ts-control > input {
    font-size: 14px;
    color: var(--text);
}
.ts-dropdown {
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
    margin-top: 4px;
    font-size: 14px;
}
.ts-dropdown .active {
    background: rgba(239, 73, 35, 0.08);
    color: var(--text);
}
.ts-dropdown .option:hover {
    background: rgba(239, 73, 35, 0.04);
}
/* In .toolbar (the filter row above tables) the form is flex with small gaps;
   Tom Select wrappers default to width:100% which breaks the layout. */
.toolbar form .ts-wrapper {
    width: auto;
    min-width: 200px;
}

/* For selects that hold long option labels (e.g. the episode picker in the
   narrow sidebar of /panel/titles/{id}), let the dropdown panel expand past
   its 320px wrapper so the full names are readable.
   With `dropdownParent: 'body'` (set in panel-searchable-select.js) the
   dropdown is now a child of <body>, so we use `!important` to override the
   inline width that Tom Select assigns based on the original wrapper width. */
.ts-dropdown.wide-dropdown,
.wide-dropdown.ts-dropdown {
    min-width: 520px !important;
    width: 520px !important;
    max-width: 90vw !important;
}
/* Inside a wide dropdown, let option text wrap onto two lines if needed
   instead of getting clipped with ellipsis. */
.ts-dropdown.wide-dropdown .option,
.wide-dropdown.ts-dropdown .option {
    white-space: normal;
    text-overflow: clip;
    overflow: visible;
    line-height: 1.3;
}
