/* ==========================================================================
   Base
   ========================================================================== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Hiragino Sans", Meiryo, sans-serif;
    background: #f0f2f5;
    color: #333;
    line-height: 1.6;
}

a {
    color: #3498db;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* ==========================================================================
   Layout
   ========================================================================== */
.container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 24px 16px;
}

/* ==========================================================================
   Header
   ========================================================================== */
.app-header {
    background: #2c3e50;
    color: #fff;
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.header-title {
    color: #fff;
    font-size: 18px;
    font-weight: bold;
    text-decoration: none;
}

.header-title:hover {
    text-decoration: none;
    opacity: 0.9;
}

.app-header nav a {
    color: #ecf0f1;
    margin-left: 16px;
    font-size: 14px;
}

.app-header nav a:hover {
    color: #fff;
    text-decoration: underline;
}

/* ==========================================================================
   Login
   ========================================================================== */
.login-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: #f0f2f5;
}

.login-box {
    background: #fff;
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
    width: 100%;
    max-width: 400px;
}

.login-box h1 {
    text-align: center;
    font-size: 20px;
    margin-bottom: 24px;
    color: #2c3e50;
}

/* ==========================================================================
   Forms
   ========================================================================== */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 4px;
    color: #555;
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="date"],
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d0d0d0;
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.15);
}

.checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    cursor: pointer;
    margin-right: 12px;
    margin-bottom: 4px;
}

.notice-checkboxes {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 0;
}

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn-primary {
    background: #3498db;
    color: #fff;
    border: none;
    padding: 10px 24px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
    transition: background 0.2s;
}

.btn-primary:hover {
    background: #2980b9;
}

.btn-primary:disabled {
    background: #a0c4e8;
    cursor: not-allowed;
}

.btn-secondary {
    background: #fff;
    color: #555;
    border: 1px solid #d0d0d0;
    padding: 10px 24px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 15px;
    transition: background 0.2s;
    text-decoration: none;
    display: inline-block;
}

.btn-secondary:hover {
    background: #f5f5f5;
    text-decoration: none;
}

.btn-accent {
    background: #27ae60;
    color: #fff;
    border: none;
    padding: 10px 24px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
    transition: background 0.2s;
}

.btn-accent:hover {
    background: #219a52;
}

.btn-sm {
    padding: 5px 12px;
    font-size: 13px;
    border-radius: 4px;
    border: 1px solid #d0d0d0;
    background: #fff;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-sm:hover {
    background: #f0f0f0;
}

.btn-primary.btn-sm {
    background: #3498db;
    color: #fff;
    border-color: #3498db;
}

.btn-primary.btn-sm:hover {
    background: #2980b9;
    border-color: #2980b9;
}

.btn-full {
    width: 100%;
}

.btn-remove {
    background: none;
    border: none;
    color: #999;
    font-size: 18px;
    cursor: pointer;
    padding: 2px 6px;
    line-height: 1;
}

.btn-remove:hover {
    color: #e74c3c;
}

/* ==========================================================================
   Alerts
   ========================================================================== */
.alert {
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 16px;
    font-size: 14px;
}

.alert-error {
    background: #fce4e4;
    color: #c0392b;
    border: 1px solid #e6b0aa;
}

/* ==========================================================================
   Page Header
   ========================================================================== */
.page-header {
    margin-bottom: 20px;
}

.page-header h2 {
    font-size: 22px;
    color: #2c3e50;
}

.subtitle {
    font-size: 14px;
    color: #888;
    margin-top: 2px;
}

/* ==========================================================================
   Brand Form
   ========================================================================== */
.brand-form {
    background: #fff;
    padding: 24px;
    border-radius: 10px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
    max-width: 480px;
}

/* ==========================================================================
   Cast Grid (Selection Page)
   ========================================================================== */
.cast-selection-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
}

.selected-count {
    font-size: 14px;
    color: #555;
    margin-left: 8px;
}

.cast-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}

/* --- Mobile optimizations --- */
@media (max-width: 600px) {

    /* Header: wrap nav links */
    .app-header {
        flex-wrap: wrap;
        gap: 6px;
        padding: 10px 14px;
    }

    .header-title {
        font-size: 15px;
    }

    .app-header nav a {
        margin-left: 10px;
        font-size: 13px;
    }

    /* Cast grid: 2 columns on mobile */
    .cast-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    .cast-info {
        padding: 6px 8px;
        font-size: 11px;
    }

    .cast-info strong {
        font-size: 12px;
    }

    .cast-info .time {
        font-size: 11px;
    }

    /* Container padding */
    .container {
        padding: 16px 10px;
    }

    /* Page header */
    .page-header h2 {
        font-size: 18px;
    }
}

.cast-card-select {
    cursor: pointer;
    display: block;
}

.cast-card-select input[type="checkbox"] {
    display: none;
}

.cast-card {
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    transition: box-shadow 0.2s, transform 0.15s;
    border: 2px solid transparent;
}

.cast-card:hover {
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.12);
    transform: translateY(-1px);
}

.cast-card-select input:checked+.cast-card {
    border-color: #3498db;
    box-shadow: 0 0 0 1px #3498db, 0 2px 8px rgba(52, 152, 219, 0.2);
}

.cast-card img {
    width: 100%;
    aspect-ratio: 3/4;
    object-fit: cover;
    display: block;
}

.cast-info {
    padding: 8px 10px;
    font-size: 12px;
    line-height: 1.5;
}

.cast-info strong {
    display: block;
    font-size: 14px;
    color: #2c3e50;
}

.cast-info .measurements {
    display: block;
    color: #777;
}

.cast-info .time {
    display: block;
    color: #e74c3c;
    font-weight: 600;
    font-size: 13px;
}

.cast-info .status-badge {
    display: inline-block;
    font-size: 11px;
    padding: 1px 6px;
    border-radius: 3px;
    background: #eee;
    color: #666;
    margin-top: 2px;
}

/* ==========================================================================
   Form Actions
   ========================================================================== */
.form-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

/* ==========================================================================
   Editor
   ========================================================================== */
.editor-section {
    background: #fff;
    border-radius: 10px;
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.editor-section h3 {
    font-size: 16px;
    color: #2c3e50;
    margin-bottom: 16px;
    border-bottom: 1px solid #eee;
    padding-bottom: 8px;
}

.drag-hint {
    font-weight: normal;
    font-size: 13px;
    color: #999;
}

/* Cast editor cards */
.cast-list-sortable {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.cast-edit-card {
    background: #fafafa;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    overflow: hidden;
    transition: box-shadow 0.2s;
}

.cast-edit-card:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.card-top-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #f0f2f5;
    border-bottom: 1px solid #e0e0e0;
}

.drag-handle {
    cursor: grab;
    font-size: 18px;
    color: #999;
    user-select: none;
}

.drag-handle:active {
    cursor: grabbing;
}

.cast-number {
    font-size: 13px;
    color: #888;
    font-weight: 600;
}

.card-body {
    display: grid;
    grid-template-columns: 200px 1fr;
    gap: 16px;
    padding: 16px;
}

@media (max-width: 700px) {
    .card-body {
        grid-template-columns: 1fr;
    }
}

/* Image section */
.image-section {}

.selected-image img {
    width: 100%;
    max-width: 180px;
    border-radius: 6px;
    display: block;
}

.image-thumbnails {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.image-thumbnails .thumb {
    width: 44px;
    height: 44px;
    object-fit: cover;
    border-radius: 4px;
    cursor: pointer;
    border: 2px solid transparent;
    opacity: 0.6;
    transition: opacity 0.2s, border-color 0.2s;
}

.image-thumbnails .thumb:hover {
    opacity: 0.9;
}

.image-thumbnails .thumb.selected {
    border-color: #3498db;
    opacity: 1;
}

/* Card controls */
.card-controls {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.cast-details .cast-name {
    font-size: 16px;
    color: #2c3e50;
    display: block;
}

.cast-details .measurements {
    font-size: 13px;
    color: #777;
    display: block;
}

.cast-details .time {
    font-size: 14px;
    color: #e74c3c;
    font-weight: 600;
    display: block;
}

/* Labels */
.label-section {
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.section-label {
    font-size: 13px;
    color: #888;
    white-space: nowrap;
    padding-top: 4px;
}

.label-selector {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.label-badge {
    padding: 3px 10px;
    border-radius: 12px;
    border: 1px solid var(--label-bg);
    background: #fff;
    color: var(--label-bg);
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    transition: all 0.15s;
}

.label-badge:hover {
    opacity: 0.85;
}

.label-badge.active {
    background: var(--label-bg);
    color: var(--label-color);
}

/* Catchphrase */
.catchphrase-section {
    border-top: 1px solid #eee;
    padding-top: 10px;
}

.catchphrase-options {
    margin-top: 8px;
}

.catchphrase-candidates {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin: 8px 0;
}

.catchphrase-candidate {
    text-align: left;
    padding: 6px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    background: #fff;
    font-size: 13px;
    transition: all 0.15s;
    width: 100%;
}

.catchphrase-candidate:hover {
    border-color: #3498db;
    background: #f5faff;
}

.catchphrase-candidate.selected {
    border-color: #3498db;
    background: #ebf5fb;
    font-weight: 600;
}

.catchphrase-manual {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #d0d0d0;
    border-radius: 4px;
    font-size: 13px;
    margin-top: 6px;
}

.catchphrase-manual:focus {
    outline: none;
    border-color: #3498db;
}

/* Sortable ghost */
.sortable-ghost {
    opacity: 0.4;
    border: 2px dashed #3498db !important;
}

/* ==========================================================================
   Editor Actions
   ========================================================================== */
.editor-actions {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-top: 20px;
    flex-wrap: wrap;
}

/* ==========================================================================
   Modal
   ========================================================================== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
}

.modal-content {
    position: relative;
    background: #fff;
    border-radius: 12px;
    width: 95%;
    max-width: 700px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #eee;
}

.modal-header h3 {
    margin: 0;
    font-size: 16px;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #999;
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    padding: 16px 20px;
    border-top: 1px solid #eee;
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

/* ==========================================================================
   Toast
   ========================================================================== */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: #27ae60;
    color: #fff;
    padding: 12px 28px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 2000;
    animation: toastIn 0.3s ease;
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(16px);
    }

    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* ==========================================================================
   History
   ========================================================================== */
.history-filter {
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.history-filter label {
    font-size: 14px;
    color: #555;
}

.history-filter select {
    padding: 6px 10px;
    border: 1px solid #d0d0d0;
    border-radius: 4px;
    font-size: 14px;
}

.history-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.history-table th {
    background: #f5f5f5;
    padding: 10px 12px;
    text-align: left;
    font-size: 13px;
    color: #666;
    border-bottom: 1px solid #e0e0e0;
}

.history-table td {
    padding: 10px 12px;
    font-size: 14px;
    border-bottom: 1px solid #f0f0f0;
}

.history-table tr:last-child td {
    border-bottom: none;
}

.history-table tr:hover td {
    background: #fafafa;
}

/* ==========================================================================
   Detail
   ========================================================================== */
.detail-meta {
    background: #fff;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 16px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.detail-meta p {
    margin-bottom: 4px;
    font-size: 14px;
}

.detail-actions {
    margin-bottom: 20px;
    display: flex;
    gap: 12px;
}

.preview-container {
    margin-bottom: 20px;
}

.html-display {
    background: #f8f8f8;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 16px;
    overflow-x: auto;
    margin-bottom: 20px;
}

.html-display pre {
    font-size: 12px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-all;
}

/* ==========================================================================
   Empty State
   ========================================================================== */
.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: #888;
}

.empty-state p {
    margin-bottom: 16px;
    font-size: 15px;
}

/* =============================================
   Template Carousel
   ============================================= */
.template-carousel {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding: 8px 2px 12px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

.template-carousel::-webkit-scrollbar {
    height: 6px;
}

.template-carousel::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

.template-card {
    flex: 0 0 110px;
    cursor: pointer;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    overflow: hidden;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: #fff;
}

.template-card:hover {
    border-color: #999;
}

.template-card.selected {
    border-color: #3498db;
    border-width: 3px;
    box-shadow: 0 4px 16px rgba(52, 152, 219, 0.3);
    transform: translateY(-2px);
    position: relative;
}

.template-card.selected::after {
    content: "✓";
    position: absolute;
    top: -8px;
    right: -8px;
    width: 24px;
    height: 24px;
    background: #3498db;
    color: #fff;
    border-radius: 50%;
    font-size: 14px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.template-mini-preview {
    width: 100%;
    height: 100px;
    overflow: hidden;
    position: relative;
    background: #f8f8f8;
}

.tmpl-header {
    height: 16px;
    width: 100%;
}

.tmpl-body {
    padding: 6px 8px;
}

.tmpl-line {
    height: 4px;
    border-radius: 2px;
    background: #ddd;
    margin-bottom: 4px;
    width: 80%;
}

.tmpl-line-title {
    width: 50%;
    margin: 0 auto 6px;
    height: 5px;
}

.tmpl-row {
    display: flex;
    gap: 4px;
    margin-bottom: 5px;
    align-items: flex-start;
}

.tmpl-img {
    width: 20px;
    height: 20px;
    background: #ddd;
    border-radius: 2px;
    flex-shrink: 0;
}

.tmpl-text {
    flex: 1;
    min-width: 0;
}

.tmpl-text .tmpl-line {
    height: 3px;
    margin-bottom: 3px;
}

.tmpl-btn {
    width: 40px;
    height: 8px;
    border-radius: 4px;
    margin: 4px auto 0;
}

.template-card-name {
    text-align: center;
    font-size: 11px;
    padding: 4px 2px 6px;
    font-weight: 600;
    color: #555;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* =============================================
   Manual Cast Add Section
   ============================================= */
.add-cast-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 12px;
}

.tab-btn {
    padding: 6px 16px;
    border: 1px solid #ddd;
    background: #f5f5f5;
    border-radius: 6px 6px 0 0;
    cursor: pointer;
    font-size: 13px;
    color: #666;
    transition: all 0.2s;
}

.tab-btn.active {
    background: #fff;
    border-bottom-color: #fff;
    color: #333;
    font-weight: 600;
}

.add-tab-content {
    padding: 12px 0;
}

.url-input-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.form-hint {
    display: block;
    margin-top: 4px;
    color: #999;
    font-size: 12px;
}

.required {
    color: #e74c3c;
}

.manual-form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 12px;
}

@media (max-width: 600px) {
    .manual-form-grid {
        grid-template-columns: 1fr;
    }
}