/* ============================================================
   FRIENDLY THEME — rounded, warm, playful.
   Everything here is class-driven so pages stay logic-only.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;500;600;700;800&display=swap');

[x-cloak] { display: none !important; }

/* ====== DESIGN TOKENS ====== */
:root, [data-theme="light"] {
    --bg: #f7f3ff;
    --bg-accent: radial-gradient(1200px 600px at 10% -10%, #e9d5ff33 0%, transparent 60%),
                 radial-gradient(900px 500px at 110% 10%, #fbcfe866 0%, transparent 55%);
    --surface: #ffffff;
    --surface2: #f5eefd;
    --surface3: #ebe2fa;
    --border: #e4d7f8;
    --border-strong: #c8b3ee;

    --accent: #7c3aed;
    --accent-hover: #6d28d9;
    --accent-soft: #ede4fe;
    --accent2: #ec4899;
    --accent2-soft: #fde2ef;

    --text: #1f1437;
    --text2: #5f4b82;
    --text3: #9e8ec0;

    --success: #10b981;
    --success-soft: #d1fae5;
    --warning: #f59e0b;
    --warning-soft: #fef3c7;
    --error: #ef4444;
    --error-soft: #fee2e2;
    --info: #3b82f6;
    --info-soft: #dbeafe;

    --radius-sm: 10px;
    --radius: 14px;
    --radius-lg: 20px;
    --radius-xl: 28px;
    --radius-pill: 999px;

    --shadow-xs: 0 1px 2px rgba(124, 58, 237, .06);
    --shadow: 0 4px 14px rgba(124, 58, 237, .08);
    --shadow-lg: 0 16px 40px rgba(124, 58, 237, .14);
    --shadow-glow: 0 10px 30px rgba(124, 58, 237, .30);
    --shadow-glow-pink: 0 10px 30px rgba(236, 72, 153, .30);

    --transition: .22s cubic-bezier(.4, 0, .2, 1);
    --bounce: .5s cubic-bezier(.34, 1.56, .64, 1);

    --font-body: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --gradient-primary: linear-gradient(135deg, #7c3aed 0%, #ec4899 100%);
    --gradient-soft: linear-gradient(135deg, #ede4fe 0%, #fde2ef 100%);
    --gradient-success: linear-gradient(135deg, #10b981 0%, #34d399 100%);
    --gradient-warning: linear-gradient(135deg, #f59e0b 0%, #fbbf24 100%);
}

[data-theme="dark"] {
    --bg: #16111f;
    --surface: #1e1730;
    --surface2: #261d3d;
    --surface3: #322650;
    --border: #3a2d5c;
    --border-strong: #4f3e7a;

    --accent: #a78bfa;
    --accent-hover: #c4b5fd;
    --accent-soft: rgba(167, 139, 250, .15);
    --accent2: #f472b6;
    --accent2-soft: rgba(244, 114, 182, .15);

    --text: #f5f2fb;
    --text2: #b4a8d4;
    --text3: #7a6d9d;

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow: 0 4px 14px rgba(0, 0, 0, .35);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, .5);
}

/* ====== RESET ====== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
    font-family: var(--font-body);
    background: var(--bg);
    background-image: var(--bg-accent);
    background-attachment: fixed;
    color: var(--text);
    font-size: 15px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background var(--transition), color var(--transition);
}
h1, h2, h3, h4, h5, h6 { line-height: 1.3; font-weight: 700; }
a { color: var(--accent); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--accent-hover); text-decoration: none; }
::selection { background: var(--accent-soft); color: var(--accent); }

/* Nicer scrollbar — transparent border via padding-box so it looks correct on any surface */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    background-clip: padding-box;
    border: 2px solid transparent;
    border-radius: var(--radius-pill);
}
::-webkit-scrollbar-thumb:hover { background: var(--accent); background-clip: padding-box; }
/* Firefox */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }

/* ====== BUTTONS ====== */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 11px 22px;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius-pill);
    font-family: inherit;
    font-size: 14px; font-weight: 700;
    color: var(--text);
    cursor: pointer;
    transition: transform var(--transition), box-shadow var(--transition),
                background var(--transition), border-color var(--transition), color var(--transition);
    white-space: nowrap;
    user-select: none;
}
.btn:hover {
    transform: translateY(-2px);
    border-color: var(--accent);
    color: var(--accent);
    box-shadow: var(--shadow);
}
.btn:active { transform: translateY(0); }
.btn:disabled {
    opacity: .45; cursor: not-allowed; pointer-events: none; transform: none; box-shadow: none;
}
.btn .material-icons-round { font-size: 18px; }

.btn-primary {
    background: var(--gradient-primary);
    color: #fff;
    border: none;
    box-shadow: var(--shadow);
}
.btn-primary:hover {
    color: #fff;
    transform: translateY(-3px) scale(1.02);
    box-shadow: var(--shadow-glow);
}
.btn-primary:active { transform: translateY(-1px) scale(1); }

.btn-success {
    background: var(--gradient-success); color: #fff; border: none; box-shadow: var(--shadow);
}
.btn-success:hover { color: #fff; transform: translateY(-3px) scale(1.02); box-shadow: 0 10px 30px rgba(16, 185, 129, .35); }

.btn-warning {
    background: var(--gradient-warning); color: #fff; border: none; box-shadow: var(--shadow);
}
.btn-warning:hover { color: #fff; transform: translateY(-3px) scale(1.02); box-shadow: 0 10px 30px rgba(245, 158, 11, .35); }

.btn-danger {
    color: var(--error);
    border-color: var(--error-soft);
    background: var(--surface);
}
.btn-danger:hover { background: var(--error-soft); color: var(--error); border-color: var(--error); }

.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--accent-soft); border-color: transparent; box-shadow: none; transform: translateY(-1px); }

.btn-sm { padding: 7px 14px; font-size: 12px; }
.btn-lg { padding: 14px 28px; font-size: 15px; }

/* ====== INPUTS ====== */
/* Use background-color (not shorthand) so background-image on selects survives state changes */
.input, .select, textarea.input {
    width: 100%;
    padding: 12px 16px;
    background-color: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
    outline: none;
    transition: border-color var(--transition), background-color var(--transition), box-shadow var(--transition);
}
.input:hover, .select:hover { border-color: var(--border-strong); }
.input:focus, .select:focus {
    border-color: var(--accent);
    background-color: var(--surface);
    box-shadow: 0 0 0 4px var(--accent-soft);
}
.input::placeholder { color: var(--text3); font-weight: 500; }
.input:disabled { opacity: .6; background-color: var(--surface2); cursor: not-allowed; }

textarea.input { resize: vertical; min-height: 80px; line-height: 1.5; }

/* ====== SELECT ====== */
/* Closed state fully themed with custom arrow. The opened dropdown list is
   native OS UI and cannot be fully restyled cross-browser. */
select, select.input, .select {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    padding-right: 44px;
    cursor: pointer;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 20 20' fill='none'><path d='M5 8l5 5 5-5' stroke='%239e8ec0' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'/></svg>");
    background-repeat: no-repeat;
    background-position: right 16px center;
    background-size: 14px 14px;
}
select:focus, select.input:focus {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 20 20' fill='none'><path d='M5 8l5 5 5-5' stroke='%237c3aed' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'/></svg>");
}
select::-ms-expand { display: none; }
/* Improve native option appearance where supported */
select option {
    background: var(--surface);
    color: var(--text);
    padding: 10px;
    font-size: 14px;
    font-weight: 500;
}
select option:checked {
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 700;
}

/* ====== CHECKBOX & RADIO ====== */
input[type="checkbox"],
input[type="radio"] {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    width: 22px; height: 22px;
    min-width: 22px;
    margin: 0;
    border: 2px solid var(--border-strong);
    background: var(--surface);
    cursor: pointer;
    display: inline-grid;
    place-content: center;
    flex-shrink: 0;
    transition: all var(--transition);
    vertical-align: middle;
}
input[type="checkbox"] { border-radius: 7px; }
input[type="radio"]    { border-radius: 50%; }

input[type="checkbox"]:hover,
input[type="radio"]:hover {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
input[type="checkbox"]:focus-visible,
input[type="radio"]:focus-visible {
    outline: none;
    box-shadow: 0 0 0 4px var(--accent-soft);
}

input[type="checkbox"]:checked,
input[type="radio"]:checked {
    background: var(--gradient-primary);
    border-color: transparent;
    box-shadow: 0 4px 10px rgba(124, 58, 237, .25);
}
input[type="checkbox"]:checked::before {
    content: "";
    width: 13px; height: 13px;
    background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='13' height='13' viewBox='0 0 16 16' fill='none'><path d='M3 8l3.5 3.5L13 5' stroke='white' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'/></svg>") center/contain no-repeat;
    animation: pop-check var(--bounce);
}
input[type="radio"]:checked::before {
    content: "";
    width: 10px; height: 10px;
    border-radius: 50%;
    background: #fff;
    animation: pop-check var(--bounce);
}
@keyframes pop-check { from { transform: scale(0); } }

input[type="checkbox"]:disabled,
input[type="radio"]:disabled {
    opacity: .5;
    cursor: not-allowed;
    box-shadow: none;
}

/* ====== CARDS ====== */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-xs);
    transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
}
.card-hover:hover,
.card.is-interactive:hover {
    transform: translateY(-3px);
    border-color: var(--border-strong);
    box-shadow: var(--shadow);
}
.card-compact { padding: 16px; }
.card-tight { padding: 12px; }
.card-flush { padding: 0; overflow: hidden; }

/* ====== TAGS / PILLS ====== */
.tag {
    display: inline-flex; align-items: center; gap: 4px;
    font-size: 11px; font-weight: 700;
    padding: 4px 10px;
    border-radius: var(--radius-pill);
    border: 1.5px solid transparent;
    letter-spacing: .02em;
    white-space: nowrap;
}
.tag-blue   { color: var(--info);    background: var(--info-soft);    border-color: rgba(59, 130, 246, .25); }
.tag-green  { color: var(--success); background: var(--success-soft); border-color: rgba(16, 185, 129, .25); }
.tag-red    { color: var(--error);   background: var(--error-soft);   border-color: rgba(239, 68, 68, .25); }
.tag-orange { color: var(--warning); background: var(--warning-soft); border-color: rgba(245, 158, 11, .25); }
.tag-purple { color: var(--accent);  background: var(--accent-soft);  border-color: rgba(124, 58, 237, .25); }
.tag-pink   { color: var(--accent2); background: var(--accent2-soft); border-color: rgba(236, 72, 153, .25); }

/* ====== TOAST ====== */
#toast-container {
    position: fixed; top: 24px; right: 24px; z-index: 9999;
    display: flex; flex-direction: column; gap: 10px;
}
.toast {
    display: flex; align-items: center; gap: 12px;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 18px;
    box-shadow: var(--shadow-lg);
    font-size: 14px; font-weight: 600;
    min-width: 300px; max-width: 420px;
}
.toast.success { border-color: var(--success); background: linear-gradient(var(--surface), var(--surface)) padding-box, var(--gradient-success) border-box; }
.toast.error   { border-color: var(--error); }
.toast.warning { border-color: var(--warning); }
.toast-close   { background: none; border: none; color: var(--text3); cursor: pointer; font-size: 18px; margin-left: auto; border-radius: 50%; width: 24px; height: 24px; display: inline-flex; align-items: center; justify-content: center; }
.toast-close:hover { background: var(--surface2); color: var(--text); }
.toast-undo    { background: none; border: none; color: var(--accent); cursor: pointer; font-weight: 800; font-size: 13px; }
.toast-enter   { animation: slide-in var(--bounce); }
.toast-leave   { animation: slide-out .25s ease; }
@keyframes slide-in  { from { transform: translateX(120%) scale(.9); opacity: 0; } }
@keyframes slide-out { to   { transform: translateX(120%) scale(.9); opacity: 0; } }

/* ====== LOADER ====== */
.page-loader {
    position: fixed; inset: 0; z-index: 9998;
    background: rgba(255, 255, 255, .7);
    backdrop-filter: blur(6px);
    display: flex; align-items: center; justify-content: center;
}
.loader-spinner {
    width: 44px; height: 44px;
    border: 4px solid var(--accent-soft);
    border-top-color: var(--accent);
    border-right-color: var(--accent2);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ====== PAGINATION ====== */
.pagination-bar {
    display: flex; justify-content: space-between; align-items: center;
    margin-top: 20px; gap: 12px; flex-wrap: wrap;
    font-size: 13px; font-weight: 600;
}
.pagination-bar-info { color: var(--text2); display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.pagination-per-page {
    padding: 6px 12px; font-size: 13px; font-family: inherit;
    border: 2px solid var(--border); border-radius: var(--radius);
    background: var(--surface); color: var(--text);
    cursor: pointer; outline: none;
    transition: all var(--transition);
}
.pagination-per-page:hover { border-color: var(--accent); color: var(--accent); }
.pagination { display: flex; gap: 6px; align-items: center; }
.pagination-btn {
    min-width: 36px; height: 36px;
    display: flex; align-items: center; justify-content: center;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px; font-weight: 700; font-family: inherit;
    cursor: pointer; transition: all var(--transition);
    color: var(--text);
}
.pagination-btn:hover {
    border-color: var(--accent); color: var(--accent);
    transform: translateY(-2px);
}
.pagination-btn.active {
    background: var(--gradient-primary);
    color: #fff; border-color: transparent;
    pointer-events: none;
    box-shadow: var(--shadow-glow);
}
.pagination-btn:disabled { opacity: .3; cursor: not-allowed; transform: none; }
.pagination-btn.dots { border: none; background: none; cursor: default; min-width: 20px; }
.pagination-btn.dots:hover { color: inherit; transform: none; }

/* ====== ENTITY PICKER ====== */
.ep-trigger {
    display: flex; align-items: center; justify-content: space-between;
    cursor: pointer; min-height: 44px;
}
.ep-trigger.disabled { opacity: .5; cursor: not-allowed; }
.ep-trigger .ep-placeholder { color: var(--text3); font-weight: 500; }
.ep-trigger .ep-value { font-weight: 600; }
.ep-dropdown {
    position: absolute; top: 100%; left: 0; right: 0; z-index: 60;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    margin-top: 6px; overflow: hidden;
    animation: pop-in var(--bounce);
}
@keyframes pop-in { from { opacity: 0; transform: translateY(-8px) scale(.96); } }
.ep-search { padding: 10px; border-bottom: 1px solid var(--border); }
.ep-search input {
    width: 100%; padding: 8px 12px; font-size: 13px; font-family: inherit;
    border: 2px solid var(--border); border-radius: var(--radius);
    background: var(--surface2); color: var(--text); outline: none;
    transition: all var(--transition);
}
.ep-search input:focus { border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px var(--accent-soft); }
.ep-list { max-height: 260px; overflow-y: auto; padding: 4px; }
.ep-item {
    padding: 9px 12px; font-size: 14px; font-weight: 500;
    border-radius: var(--radius-sm); cursor: pointer;
    transition: background var(--transition), color var(--transition);
}
.ep-item:hover { background: var(--surface2); color: var(--accent); }
.ep-item.selected { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.ep-hint {
    padding: 8px 12px; font-size: 12px; color: var(--text3);
    border-top: 1px solid var(--border); background: var(--surface2); text-align: center;
}
.ep-empty { padding: 20px; text-align: center; font-size: 13px; color: var(--text3); }

/* ====== SHARED UTILITY COMPONENTS ====== */
/* Stack: vertical flow of elements with consistent spacing */
.stack      { display: flex; flex-direction: column; gap: 12px; }
.stack-tight{ display: flex; flex-direction: column; gap: 6px; }
.stack-loose{ display: flex; flex-direction: column; gap: 20px; }

/* Row: horizontal flex with gap */
.row        { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.row-between{ display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.row-tight  { display: flex; align-items: center; gap: 6px; }
.row-grow > * { flex: 1; min-width: 0; }

/* Muted / subtle text */
.muted  { color: var(--text3); }
.soft   { color: var(--text2); }
.strong { font-weight: 700; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Gradient headline helper */
.gradient-text {
    background: var(--gradient-primary);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}

/* Empty state */
.empty-state {
    text-align: center; padding: 60px 24px;
    background: var(--surface);
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
}
.empty-state-icon { font-size: 56px; opacity: .4; margin-bottom: 14px; color: var(--accent); }
.empty-state-text { font-size: 15px; color: var(--text2); }

/* ====== RESPONSIVE ====== */
@media (max-width: 768px) {
    body { font-size: 14px; }
    .btn { padding: 10px 18px; font-size: 13px; }
    .btn-sm { padding: 6px 12px; font-size: 12px; }
    .card { padding: 18px; }
}
