/* ═══════════════════════════════════════════════════
   Iris Sentence Manager — Dark Theme Stylesheet
   ═══════════════════════════════════════════════════ */

:root {
    --bg-primary: #0b1120;
    --bg-secondary: #0f172a;
    --bg-card: rgba(15, 23, 42, 0.5);
    --bg-input: rgba(30, 41, 59, 0.6);
    --border: rgba(51, 65, 85, 0.4);
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent-amber: #f59e0b;
    --accent-teal: #14b8a6;
    --accent-rose: #f43f5e;
    --status-posted: #14b8a6;
    --status-draft: #64748b;
    --radius: 8px;
    --radius-lg: 12px;
    --transition: 0.2s ease;
}

/* ── Reset & Base ────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html { font-size: 15px; }

body {
    font-family: 'DM Sans', 'Noto Sans JP', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

a { color: var(--accent-teal); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Login ───────────────────────────────────── */
.login-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 2rem;
}

.login-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 3rem;
    width: 100%;
    max-width: 400px;
}

.login-logo {
    text-align: center;
    margin-bottom: 2rem;
}

.login-logo .logo-icon { font-size: 2.5rem; display: block; margin-bottom: .5rem; }
.login-logo h1 { font-size: 1.3rem; color: var(--accent-amber); font-weight: 600; }

.login-form .form-group { margin-bottom: 1.2rem; }

.error-msg {
    background: rgba(244, 63, 94, 0.12);
    border: 1px solid rgba(244, 63, 94, 0.3);
    color: var(--accent-rose);
    padding: .5rem .8rem;
    border-radius: var(--radius);
    font-size: .85rem;
    margin-bottom: 1rem;
}

/* ── Form Elements ───────────────────────────── */
.form-group { margin-bottom: 1rem; }

.form-group label {
    display: block;
    font-size: .8rem;
    color: var(--text-secondary);
    margin-bottom: .35rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: .65rem .85rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-family: inherit;
    font-size: .95rem;
    transition: border-color var(--transition);
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--accent-teal);
}

.form-group textarea { resize: vertical; }

.mono-textarea {
    font-family: 'Courier New', Consolas, monospace !important;
    font-size: .85rem !important;
    line-height: 1.5 !important;
}

/* ── Buttons ─────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: .55rem 1.1rem;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-family: inherit;
    font-size: .85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    gap: .3rem;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
    background: var(--accent-teal);
    color: #0b1120;
    border-color: var(--accent-teal);
}
.btn-primary:hover:not(:disabled) { background: #0d9488; }

.btn-accent {
    background: var(--accent-amber);
    color: #0b1120;
    border-color: var(--accent-amber);
}
.btn-accent:hover:not(:disabled) { background: #d97706; }

.btn-outline {
    background: transparent;
    color: var(--text-secondary);
    border-color: var(--border);
}
.btn-outline:hover:not(:disabled) { border-color: var(--text-secondary); color: var(--text-primary); }

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: none;
}
.btn-ghost:hover:not(:disabled) { color: var(--text-primary); }

.btn-danger-ghost {
    background: transparent;
    color: var(--accent-rose);
    border: none;
}
.btn-danger-ghost:hover:not(:disabled) { background: rgba(244, 63, 94, 0.1); }

.btn-sm { padding: .3rem .65rem; font-size: .78rem; }
.btn-block { width: 100%; }

/* ── Header ──────────────────────────────────── */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .8rem 1.5rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: .6rem;
}

.logo-icon-sm { font-size: 1.3rem; }

.header-left h1 {
    font-size: 1.05rem;
    color: var(--accent-amber);
    font-weight: 600;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1.2rem;
}

.stats-bar {
    display: flex;
    gap: 1rem;
    font-size: .8rem;
    color: var(--text-muted);
}

.stat-item b { color: var(--text-primary); }
.stat-bluesky b { color: var(--accent-teal); }
.stat-patreon b { color: var(--accent-amber); }

/* ── Toolbar ─────────────────────────────────── */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: .8rem;
    padding: 1rem 0;
}

.toolbar-left, .toolbar-right {
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-wrap: wrap;
}

.search-box input {
    padding: .5rem .8rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: .85rem;
    width: 260px;
    transition: border-color var(--transition);
}
.search-box input:focus { outline: none; border-color: var(--accent-teal); }

.filter-select {
    padding: .5rem .8rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: .82rem;
    cursor: pointer;
}
.filter-select:focus { outline: none; border-color: var(--accent-teal); }
.filter-select option { background: var(--bg-secondary); }

/* ── Dropdown ────────────────────────────────── */
.dropdown { position: relative; }

.dropdown-menu {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    min-width: 180px;
    z-index: 200;
    overflow: hidden;
}

.dropdown-menu a {
    display: block;
    padding: .6rem 1rem;
    font-size: .85rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background var(--transition);
}
.dropdown-menu a:hover {
    background: rgba(51, 65, 85, 0.3);
    color: var(--text-primary);
    text-decoration: none;
}

/* ── Main Content ────────────────────────────── */
.main-content { padding: 0 1.5rem 2rem; max-width: 1400px; margin: 0 auto; }

/* ── Data Table ──────────────────────────────── */
.table-wrapper { overflow-x: auto; }

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .85rem;
}

.data-table th {
    text-align: left;
    padding: .7rem .6rem;
    color: var(--text-muted);
    font-weight: 600;
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .5px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.data-table th.sortable { cursor: pointer; user-select: none; }
.data-table th.sortable:hover { color: var(--text-secondary); }

.data-table td {
    padding: .6rem;
    border-bottom: 1px solid rgba(51, 65, 85, 0.2);
    vertical-align: middle;
}

.clickable-row { cursor: pointer; transition: background var(--transition); }
.clickable-row:hover { background: rgba(51, 65, 85, 0.15); }

.truncate {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }

.actions-cell {
    display: flex;
    gap: .3rem;
}

/* ── Badge ───────────────────────────────────── */
.badge {
    display: inline-block;
    padding: .2rem .6rem;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 500;
    white-space: nowrap;
    transition: all var(--transition);
}

.badge-teal {
    background: rgba(20, 184, 166, 0.15);
    color: var(--accent-teal);
    border: 1px solid rgba(20, 184, 166, 0.3);
}
.badge-teal:hover { background: rgba(20, 184, 166, 0.25); }

.badge-amber {
    background: rgba(245, 158, 11, 0.15);
    color: var(--accent-amber);
    border: 1px solid rgba(245, 158, 11, 0.3);
}
.badge-amber:hover { background: rgba(245, 158, 11, 0.25); }

.badge-gray {
    background: rgba(100, 116, 139, 0.15);
    color: var(--text-muted);
    border: 1px solid rgba(100, 116, 139, 0.3);
}
.badge-gray:hover { background: rgba(100, 116, 139, 0.25); }

.badge.large { padding: .35rem .9rem; font-size: .85rem; }

/* ── P20 Count ───────────────────────────────── */
.p20-count { color: var(--text-muted); font-size: .8rem; font-weight: 500; }
.p20-count.p20-active { color: var(--accent-teal); }

/* ── Pagination ──────────────────────────────── */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 1.2rem 0;
}

.page-info { font-size: .85rem; color: var(--text-secondary); }

/* ── Detail View ─────────────────────────────── */
.detail-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 0;
}

.detail-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 2rem;
    backdrop-filter: blur(8px);
}

.detail-top {
    display: flex;
    align-items: baseline;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.detail-no {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent-amber);
}

.detail-filename { font-size: .9rem; }

.detail-body { margin-bottom: 1.5rem; }

.detail-field {
    margin-bottom: 1.2rem;
    padding-bottom: 1.2rem;
    border-bottom: 1px solid rgba(51, 65, 85, 0.2);
}
.detail-field:last-child { border-bottom: none; }

.detail-field label {
    font-size: .75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .5px;
    font-weight: 600;
    margin-bottom: .4rem;
    display: block;
}

.detail-field .en-text { font-size: 1.1rem; font-weight: 500; }
.detail-field .note-text { white-space: pre-wrap; color: var(--text-secondary); line-height: 1.8; }

.detail-status-row {
    display: flex;
    gap: 2rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.status-block { display: flex; flex-direction: column; gap: .3rem; }
.status-label { font-size: .75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; font-weight: 600; }
.status-date { font-size: .8rem; color: var(--text-muted); }

.detail-actions {
    display: flex;
    gap: .5rem;
    margin-bottom: 2rem;
}

/* ── P20 Grid (Detail) ───────────────────────── */
.p20-grid-section h3 {
    font-size: .9rem;
    color: var(--text-secondary);
    margin-bottom: .8rem;
}

.p20-grid {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: .4rem;
}

.p20-cell {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(51, 65, 85, 0.2);
    border-radius: 6px;
    font-size: .75rem;
    color: var(--text-muted);
    font-weight: 500;
    border: 1px solid rgba(51, 65, 85, 0.3);
}

.p20-cell.filled {
    background: rgba(20, 184, 166, 0.15);
    color: var(--accent-teal);
    border-color: rgba(20, 184, 166, 0.3);
}

/* ── P20 Management ──────────────────────────── */
.p20-title { font-size: 1rem; color: var(--text-secondary); font-weight: 500; }

.p20-container {
    display: flex;
    gap: 1.5rem;
    min-height: calc(100vh - 160px);
}

.p20-sidebar {
    width: 180px;
    flex-shrink: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: .5rem;
    overflow-y: auto;
    backdrop-filter: blur(8px);
}

.p20-nav-item {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .5rem .7rem;
    border-radius: 6px;
    font-size: .82rem;
    cursor: pointer;
    transition: all var(--transition);
    color: var(--text-secondary);
}

.p20-nav-item:hover { background: rgba(51, 65, 85, 0.25); }
.p20-nav-item.active {
    background: rgba(20, 184, 166, 0.12);
    color: var(--accent-teal);
}

.p20-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.dot-empty { background: var(--text-muted); opacity: .3; }
.dot-filled { background: var(--accent-teal); }

.p20-editor {
    flex: 1;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    backdrop-filter: blur(8px);
}

.p20-editor-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.p20-page-label {
    font-size: .95rem;
    font-weight: 600;
    color: var(--text-primary);
}

.p20-editor-footer {
    margin-top: 1.5rem;
    display: flex;
    justify-content: flex-end;
}

/* ── Modal ───────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
    padding: 1rem;
}

.modal-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 2rem;
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-card h2 {
    font-size: 1.2rem;
    margin-bottom: 1.5rem;
    color: var(--accent-amber);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: .5rem;
    margin-top: 1.5rem;
}

/* ── Toast ───────────────────────────────────── */
.toast {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    padding: .7rem 1.2rem;
    border-radius: var(--radius);
    font-size: .85rem;
    font-weight: 500;
    z-index: 2000;
    animation: toastIn 0.3s ease;
}

.toast.success {
    background: rgba(20, 184, 166, 0.9);
    color: #0b1120;
}
.toast.error {
    background: rgba(244, 63, 94, 0.9);
    color: #fff;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── Responsive ──────────────────────────────── */
@media (max-width: 1024px) {
    .p20-container { flex-direction: column; }
    .p20-sidebar {
        width: 100%;
        flex-direction: row;
        display: flex;
        flex-wrap: wrap;
        gap: .3rem;
        padding: .5rem;
    }
    .p20-nav-item { flex: 0 0 auto; }
}

@media (max-width: 768px) {
    .app-header { flex-direction: column; gap: .5rem; padding: .6rem 1rem; }
    .header-right { width: 100%; justify-content: space-between; }
    .stats-bar { font-size: .7rem; gap: .5rem; }
    .toolbar { flex-direction: column; align-items: stretch; }
    .toolbar-left, .toolbar-right { flex-wrap: wrap; }
    .search-box input { width: 100%; }
    .main-content { padding: 0 .8rem 1.5rem; }
    .detail-card { padding: 1.2rem; }
    .modal-card { padding: 1.5rem; }
    .p20-grid { grid-template-columns: repeat(5, 1fr); }
}
