* { box-sizing: border-box; }
body {
    font-family: Inter, system-ui, -apple-system, sans-serif;
    margin: 0;
    color: #0f172a;
    background: linear-gradient(180deg, #f8fafc 0%, #eef2ff 100%);
}
.main { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }
.muted { color: #64748b; }
.page-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(140px, 1fr));
    gap: 0.8rem;
    margin-bottom: 1rem;
}
.kpi-card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    padding: 0.8rem 0.9rem;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.05);
}
.kpi-label { display: block; font-size: 0.8rem; color: #64748b; }
.kpi-value { display: block; margin-top: 0.2rem; font-size: 1.35rem; letter-spacing: -0.02em; }
.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.5rem;
}
.tag {
    display: inline-block;
    border: 1px solid #cbd5e1;
    color: #334155;
    border-radius: 999px;
    padding: 0.2rem 0.6rem;
    font-size: 0.78rem;
    background: #f8fafc;
}
.nav {
    position: sticky;
    top: 0;
    z-index: 20;
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(8px);
    color: #fff;
    padding: 0.85rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}
.nav a {
    color: #c7d2fe;
    text-decoration: none;
    font-weight: 600;
    padding: 0.35rem 0.6rem;
    border-radius: 8px;
}
.nav a:hover { color: #fff; background: rgba(255,255,255,0.12); }
.nav-logo { display: flex; align-items: center; padding: 0.2rem 0.5rem 0.2rem 0; margin-right: 0.25rem; }
.nav-logo:hover { background: transparent; }
.nav-logo-img { height: 56px; width: auto; display: block; filter: brightness(1.25) contrast(1.05); }
.nav-user { margin-left: auto; font-size: 0.9rem; color: #cbd5e1; }
.nav strong { color: #fff; letter-spacing: -0.01em; }

.login-brand { text-align: center; margin: 2rem 0 1rem; }
.login-logo { height: 120px; width: auto; display: inline-block; }

h1 { margin-top: 0; margin-bottom: 1rem; letter-spacing: -0.02em; }
h2 { margin: 0 0 1rem; letter-spacing: -0.01em; }

.card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    padding: 1.25rem;
    margin: 1.25rem 0;
    box-shadow: 0 10px 25px rgba(15, 23, 42, 0.06);
}
.card.narrow { max-width: 380px; margin: 2rem auto; }

.table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.05);
}
.table-wrap {
    width: 100%;
    border-radius: 14px;
}
.table th, .table td {
    padding: 0.75rem 0.9rem;
    text-align: left;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: top;
}
.table th {
    background: #f8fafc;
    font-weight: 700;
    color: #334155;
    font-size: 0.92rem;
}
.table tbody tr:hover { background: #f8fafc; }

.cell-title { font-weight: 600; color: #0f172a; }
.cell-sub { color: #64748b; font-size: 0.86rem; margin-top: 0.15rem; }

.status {
    display: inline-block;
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
}
.status-active { background: #dcfce7; color: #166534; }
.status-incomplete { background: #fef3c7; color: #92400e; }
.status-pending { background: #e2e8f0; color: #334155; }
.status-running { background: #dbeafe; color: #1d4ed8; }
.status-completed { background: #dcfce7; color: #166534; }
.status-failed { background: #fee2e2; color: #b91c1c; }

.form { margin-top: 0.25rem; }
.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(220px, 1fr));
    gap: 0.8rem 1rem;
}
.form label {
    display: flex;
    flex-direction: column;
    font-weight: 600;
    color: #334155;
    gap: 0.35rem;
}
.span-2 { grid-column: span 2; }
.form input, .form select {
    width: 100%;
    margin: 0;
    padding: 0.58rem 0.7rem;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    background: #fff;
}
.form input:focus, .form select:focus {
    outline: none;
    border-color: #4f46e5;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}
.form button {
    margin-top: 0.6rem;
    padding: 0.62rem 0.95rem;
    background: #334155;
    color: #fff;
    border: none;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
}
.form button:hover { background: #1e293b; }
.btn-primary {
    margin-top: 1rem;
    padding: 0.65rem 1rem;
    background: #4f46e5;
    color: #fff;
    border: none;
    border-radius: 10px;
    font-weight: 700;
    cursor: pointer;
}
.btn-primary:hover { background: #4338ca; }
.btn-secondary {
    padding: 0.55rem 0.9rem;
    background: #fff;
    color: #475569;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    margin-left: 0.5rem;
}
.btn-secondary:hover { background: #f8fafc; border-color: #94a3b8; color: #334155; }
.btn-danger {
    padding: 0.4rem 0.7rem;
    background: #dc2626;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    font-size: 0.85rem;
}
.btn-danger:hover { background: #b91c1c; }
.btn-small { padding: 0.4rem 0.7rem; font-size: 0.85rem; }
.inline-form { display: inline; }
.inline-form-label { display: inline; margin-right: 0.5rem; font-weight: normal; white-space: nowrap; }

/* Reseller edit form (inline in table) – full width */
.reseller-edit-row .reseller-edit-cell {
    padding: 0;
    vertical-align: top;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
    width: 100%;
    box-sizing: border-box;
}
.reseller-edit-panel {
    margin: 0;
    padding: 1.25rem 1.5rem;
    width: 100%;
    max-width: none;
    box-sizing: border-box;
}
.reseller-edit-title {
    margin: 0 0 1.25rem;
    font-size: 1.1rem;
    font-weight: 700;
    color: #1e293b;
    letter-spacing: -0.01em;
}
.reseller-edit-form .form-grid { margin-bottom: 0; }
.reseller-edit-section {
    margin-bottom: 1.5rem;
}
.reseller-edit-section:last-of-type { margin-bottom: 1rem; }
.reseller-edit-section-title {
    margin: 0 0 0.6rem;
    font-size: 0.8rem;
    font-weight: 700;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.reseller-edit-section .form-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(180px, 1fr));
    gap: 0.7rem 1.2rem;
}
.reseller-edit-section .form-grid .span-2 { grid-column: span 2; }
.reseller-edit-textarea {
    width: 100%;
    min-height: 120px;
    font-family: ui-monospace, monospace;
    font-size: 0.88rem;
    padding: 0.6rem 0.75rem;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    resize: vertical;
}
.reseller-edit-textarea:focus {
    outline: none;
    border-color: #4f46e5;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}
.reseller-edit-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid #e2e8f0;
    margin-top: 0.25rem;
}
.reseller-edit-actions .btn-primary { margin-top: 0; margin-left: 0; }
.reseller-edit-actions .btn-secondary { margin-top: 0; }

.action-link {
    color: #2563eb;
    font-weight: 600;
    text-decoration: none;
    margin-right: 0.6rem;
}
.action-link:hover { text-decoration: underline; }

.error { color: #b91c1c; margin: 0.45rem 0; }
.debug-msg { font-size: 0.75rem; color: #b91c1c; max-width: 280px; word-break: break-word; margin-top: 0.25rem; }
.debug-error { cursor: help; }
.debug-box { font-size: 0.75rem; background: #fef3c7; border: 1px solid #f59e0b; border-radius: 6px; padding: 0.5rem 0.6rem; margin-top: 0.5rem; max-width: 420px; }
.debug-box ul { margin: 0.25rem 0 0 1rem; padding: 0; }
.debug-box li { margin: 0.2rem 0; word-break: break-all; }
.debug-box code { font-size: 0.7rem; background: #fff; padding: 0.1rem 0.3rem; border-radius: 3px; }
.message {
    background: #dcfce7;
    color: #166534;
    border: 1px solid #86efac;
    padding: 0.7rem 0.8rem;
    border-radius: 10px;
    margin: 0.75rem 0;
}
.message.error {
    background: #fee2e2;
    color: #991b1b;
    border-color: #fecaca;
}
.hint { font-size: 0.9rem; color: #64748b; margin-top: 0.7rem; }

.domain-combo .domain-combo-inputs { display: flex; align-items: center; gap: 0.25rem; flex-wrap: wrap; }
.domain-combo .domain-combo-inputs input[type="text"] { flex: 1; min-width: 8rem; }
.domain-combo-sep { color: #64748b; }
.domain-combo-suffix { color: #475569; font-size: 0.95rem; }

.log {
    background: #0f172a;
    color: #e2e8f0;
    padding: 1rem;
    overflow-x: auto;
    font-size: 0.85rem;
    line-height: 1.45;
    border-radius: 8px;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 70vh;
    overflow-y: auto;
}
/* Actions dropdown in table */
.actions-td {
    min-width: 0;
}
.dropdown {
    position: relative;
    display: inline-block;
}
.dropdown-trigger {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.35rem 0.65rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: #334155;
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    cursor: pointer;
}
.dropdown-trigger:hover {
    background: #e2e8f0;
    color: #0f172a;
}
.dropdown-menu {
    display: none;
    position: fixed;
    min-width: 180px;
    max-height: 80vh;
    overflow-y: auto;
    padding: 0.35rem 0;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    box-shadow: 0 10px 25px rgba(15, 23, 42, 0.12);
    z-index: 1000;
}
.dropdown.is-open .dropdown-menu {
    display: block;
}
.dropdown-menu a,
.dropdown-item-btn {
    display: block;
    width: 100%;
    padding: 0.45rem 1rem;
    font-size: 0.875rem;
    color: #334155;
    text-align: left;
    text-decoration: none;
    border: none;
    background: none;
    cursor: pointer;
}
.dropdown-menu a:hover,
.dropdown-item-btn:hover {
    background: #f1f5f9;
    color: #0f172a;
}
.dropdown-menu form {
    margin: 0;
}
.dropdown-menu .dropdown-item-btn {
    font-family: inherit;
}
.dropdown-item-danger {
    color: #b91c1c;
    font-weight: 600;
}
.dropdown-item-danger:hover {
    background: #fef2f2;
    color: #991b1b;
}
.dropdown-sep {
    height: 1px;
    margin: 0.35rem 0.5rem;
    background: #e2e8f0;
}
.dropdown-form-upgrade {
    padding: 0.5rem 1rem;
}
.dropdown-form-upgrade select {
    width: 100%;
    margin-bottom: 0.4rem;
    padding: 0.3rem 0.5rem;
    font-size: 0.85rem;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
}
.dropdown-form-inline {
    padding: 0.5rem 1rem;
}
.dropdown-form-inline select,
.dropdown-input {
    width: 100%;
    margin-bottom: 0.4rem;
    padding: 0.3rem 0.5rem;
    font-size: 0.85rem;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
}
.inline { display: inline; }
.inline-upgrade { white-space: nowrap; }
.inline-upgrade select {
    max-width: 160px;
    padding: 0.25rem 0.4rem;
    font-size: 0.85rem;
    vertical-align: middle;
    margin-right: 0.25rem;
}
.btn-link {
    background: none;
    border: none;
    color: #475569;
    cursor: pointer;
    text-decoration: underline;
    padding: 0;
    font-size: 0.9rem;
}
.btn-link.danger { color: #b91c1c; font-weight: 600; }
code {
    background: #eef2ff;
    color: #3730a3;
    padding: 0.12rem 0.35rem;
    border-radius: 6px;
    font-size: 0.85em;
}
.cname-cell code.cname-record {
    word-break: break-all;
    display: inline-block;
    max-width: 100%;
}

/* Default courses (S3) block */
.default-courses-card {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 1rem 1.1rem;
    margin-top: 0.25rem;
}
.default-courses-header {
    display: block;
    margin-bottom: 0.75rem;
}
.default-courses-title {
    display: block;
    font-weight: 700;
    font-size: 1rem;
    color: #1e293b;
    letter-spacing: -0.01em;
}
.default-courses-subtitle {
    display: block;
    font-size: 0.8rem;
    color: #64748b;
    margin-top: 0.15rem;
    font-weight: 500;
}
.default-courses-block { margin-top: 0; }
.course-list-s3-url-row {
    margin-bottom: 0.75rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid #e2e8f0;
}
.course-list-s3-url-row .s3-url-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: #475569;
    margin-bottom: 0.35rem;
}
.s3-url-input-wrap {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}
.s3-url-input {
    flex: 1;
    min-width: 200px;
    padding: 0.5rem 0.85rem;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-size: 0.9rem;
    background: #fff;
    font-family: inherit;
}
.s3-url-input:focus {
    outline: none;
    border-color: #4f46e5;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}
.s3-url-status {
    display: block;
    font-size: 0.82rem;
    color: #64748b;
    margin-top: 0.35rem;
}
.s3-url-status:not(:empty) { font-weight: 500; }
.course-list-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.6rem 1rem;
    margin-bottom: 0.6rem;
    padding-bottom: 0.6rem;
    border-bottom: 1px solid #e2e8f0;
}
.course-search-wrap {
    flex: 1;
    min-width: 200px;
}
.course-search-input {
    width: 100%;
    padding: 0.5rem 0.85rem;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-size: 0.9rem;
    background: #fff;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.course-search-input::placeholder { color: #94a3b8; }
.course-search-input:focus {
    outline: none;
    border-color: #4f46e5;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}
.course-list-actions {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.course-list-actions .btn-small {
    padding: 0.4rem 0.7rem;
    font-size: 0.82rem;
    background: #fff;
    color: #475569;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.course-list-actions .btn-small:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
    color: #334155;
}
.course-list-actions .btn-small:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.35);
}
.course-list-meta {
    font-size: 0.85rem;
    color: #64748b;
    margin-left: auto;
    font-weight: 500;
}
.course-list-meta strong { color: #4f46e5; font-weight: 600; }
.course-list-wrap {
    height: 280px;
    overflow-y: auto;
    overflow-x: hidden;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #fff;
    padding: 0;
    -webkit-overflow-scrolling: touch;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}
.course-list-wrap::-webkit-scrollbar { width: 10px; }
.course-list-wrap::-webkit-scrollbar-track { background: #f1f5f9; border-radius: 0 10px 10px 0; }
.course-list-wrap::-webkit-scrollbar-thumb { background: #94a3b8; border-radius: 5px; }
.course-list-wrap::-webkit-scrollbar-thumb:hover { background: #64748b; }
.course-list-wrap { scrollbar-width: thin; scrollbar-color: #94a3b8 #f1f5f9; }
.course-item {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    flex-direction: row !important;
    gap: 0.6rem;
    padding: 0.55rem 0.85rem;
    cursor: pointer;
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
    font: inherit;
    color: inherit;
    border-left: 3px solid transparent;
    transition: background 0.12s, border-color 0.12s;
}
.course-item:nth-child(even) { background: rgba(248, 250, 252, 0.7); }
.course-item:hover { background: #eef2ff; }
.course-item:has(input:checked) {
    background: #e0e7ff;
    border-left-color: #4f46e5;
}
.course-item:focus-within { background: #eef2ff; }
.course-item input[type="checkbox"] {
    flex-shrink: 0;
    margin: 0;
    width: 1.15em;
    height: 1.15em;
    accent-color: #4f46e5;
    cursor: pointer;
}
.course-item-name {
    flex: 1;
    min-width: 0;
    font-weight: 500;
    color: #334155;
    word-break: break-word;
    text-align: left;
    line-height: 1.35;
}
.course-list-empty {
    padding: 2rem 1rem;
    text-align: center;
    color: #64748b;
    font-size: 0.9rem;
    display: none;
    margin: 0;
}
.course-list-empty.visible { display: block; }
.course-list-hint {
    font-size: 0.82rem;
    color: #64748b;
    margin-top: 0.5rem;
    margin-bottom: 0;
    line-height: 1.4;
}

@media (max-width: 900px) {
    .kpi-grid { grid-template-columns: repeat(2, minmax(120px, 1fr)); }
    .form-grid { grid-template-columns: 1fr; }
    .reseller-edit-section .form-grid { grid-template-columns: 1fr; }
    .span-2 { grid-column: span 1; }
    .default-courses-card { padding: 0.85rem 1rem; }
    .course-list-toolbar { flex-direction: column; align-items: stretch; padding-bottom: 0.5rem; }
    .course-search-wrap { min-width: 0; }
    .course-list-meta { margin-left: 0; }
    .reseller-edit-panel { padding: 1rem; }
}
