:root {
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --danger-color: #ef4444;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* Header */
.app-header {
    background-color: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 2rem;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

h1 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-main);
}

.controls {
    display: flex;
    gap: 1rem;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
}

.btn-secondary {
    background-color: white;
    color: var(--text-main);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background-color: #f1f5f9;
}

.btn-danger {
    background-color: transparent;
    color: var(--danger-color);
    border: 1px solid var(--border-color);
}

.btn-danger:hover {
    background-color: #fef2f2;
    border-color: var(--danger-color);
}

/* Main Content */
.app-main {
    padding: 2rem;
    display: flex;
    justify-content: center;
}

/* A4 Container */
.a4-container {
    background: var(--card-bg);
    width: 210mm;
    min-height: 297mm;
    padding: 20mm 15mm;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    border-radius: 4px;
    position: relative;
    /* ensure content scales nicely inside */
    margin: 0 auto;
}

.document-header {
    margin-bottom: 2rem;
    text-align: center;
}

.doc-title {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    outline: none;
    border-bottom: 1px dashed transparent;
    transition: border-color 0.2s;
}

.doc-title:focus,
.doc-title:hover {
    border-bottom-color: var(--border-color);
}

.doc-meta {
    display: flex;
    justify-content: space-between;
    font-size: 0.875rem;
    color: var(--text-muted);
}

.meta-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.meta-input {
    border: none;
    border-bottom: 1px solid var(--border-color);
    font-family: inherit;
    font-size: 0.875rem;
    padding: 0.25rem;
    outline: none;
    background: transparent;
}

.meta-input:focus {
    border-bottom-color: var(--primary-color);
}

/* Table */
.schedule-table-wrap {
    width: 100%;
}

.schedule-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

.schedule-table th,
.schedule-table td {
    border: 1px solid var(--border-color);
    padding: 0.5rem;
    vertical-align: top;
}

.schedule-table th {
    background-color: #f8fafc;
    font-weight: 600;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.sub-label {
    display: block;
    font-size: 0.65rem;
    font-weight: normal;
}

/* Column Widths */
.col-drag {
    width: 30px;
    text-align: center;
    border-right: none !important;
}

.col-time {
    width: 100px;
}

.col-duration {
    width: 70px;
    text-align: center;
    vertical-align: middle !important;
}

.col-photo {
    width: 140px;
}

.col-text {
    width: auto;
}

.col-note {
    width: 150px;
}

.col-action {
    width: 40px;
    text-align: center;
    vertical-align: middle !important;
    border-left: none !important;
}

/* Row Elements */
.drag-handle {
    cursor: grab;
    color: #cbd5e1;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    margin-top: 10px;
}

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

.time-inputs {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    align-items: center;
}

.time-input {
    width: 100%;
    padding: 0.25rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-family: inherit;
    font-size: 0.8rem;
    text-align: center;
}

.time-separator {
    color: var(--text-muted);
}

.duration-display {
    font-weight: 600;
    color: var(--primary-color);
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
}

.photo-dropzone {
    width: 100%;
    height: 90px;
    border: 2px dashed var(--border-color);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    background-color: #f8fafc;
    transition: all 0.2s;
    cursor: pointer;
    overflow: hidden;
}

.photo-dropzone.dragover {
    background-color: #eff6ff;
    border-color: var(--primary-color);
}

.dropzone-text {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
    pointer-events: none;
}

.preview-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    position: absolute;
    top: 0;
    left: 0;
}

.remove-photo-btn {
    position: absolute;
    top: 2px;
    right: 2px;
    background: rgba(0, 0, 0, 0.5);
    color: white;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.remove-photo-btn:hover {
    background: rgba(0, 0, 0, 0.8);
}

textarea.auto-expand {
    width: 100%;
    min-height: 90px;
    border: 1px solid transparent;
    resize: none;
    font-family: inherit;
    font-size: 0.875rem;
    padding: 0.25rem;
    background: transparent;
    line-height: 1.5;
}

textarea.auto-expand:focus,
textarea.auto-expand:hover {
    border-color: var(--border-color);
    outline: none;
    border-radius: 4px;
}

.delete-row-btn {
    background: transparent;
    border: none;
    color: #cbd5e1;
    cursor: pointer;
    transition: color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.delete-row-btn:hover {
    color: var(--danger-color);
}

.document-footer {
    margin-top: 2rem;
    font-size: 0.875rem;
    color: var(--text-muted);
}

.document-footer p {
    outline: none;
    border: 1px dashed transparent;
    padding: 0.5rem;
}

.document-footer p:hover,
.document-footer p:focus {
    border-color: var(--border-color);
}

/* Highlight drag ghost */
.sortable-ghost {
    opacity: 0.4;
    background-color: #f1f5f9;
}

/* Print Styles */
@media print {
    body {
        background: none;
    }

    .no-print {
        display: none !important;
    }

    .a4-container {
        box-shadow: none;
        width: 100%;
        margin: 0;
        padding: 0;
        min-height: auto;
    }

    .schedule-table th,
    .schedule-table td {
        border: 1px solid #000;
    }

    .photo-dropzone {
        border: 1px solid #000;
        background: transparent;
    }

    textarea.auto-expand {
        border: none !important;
    }

    /* Hide specific columns totally */
    .col-drag,
    .col-action {
        width: 0 !important;
        padding: 0 !important;
        border: none !important;
    }

    /* Adjust input styles for print */
    input,
    textarea {
        background: transparent !important;
    }
}

@media (max-width: 700px) {
    body {
        overflow-x: hidden;
    }

    .app-header {
        position: static;
        padding: 0.875rem;
    }

    .header-content {
        display: block;
    }

    .header-content h1 {
        margin-bottom: 0.875rem;
    }

    .controls {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.5rem;
    }

    .btn {
        justify-content: center;
        min-height: 44px;
        padding: 0.625rem;
        white-space: normal;
    }

    #reset-btn {
        grid-column: 1 / -1;
    }

    .app-main {
        display: block;
        padding: 0.75rem;
    }

    .a4-container {
        width: 100%;
        min-height: auto;
        margin: 0;
        padding: 1.5rem 0.75rem;
    }

    .document-header {
        margin-bottom: 1.25rem;
        text-align: left;
    }

    .doc-meta {
        flex-direction: column;
        gap: 0.75rem;
    }

    .meta-item {
        align-items: flex-start;
        flex-direction: column;
        gap: 0.25rem;
    }

    .meta-input {
        width: 100%;
    }

    .schedule-table-wrap {
        overflow-x: auto;
        overscroll-behavior-inline: contain;
        -webkit-overflow-scrolling: touch;
    }

    .schedule-table {
        min-width: 680px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
