* { box-sizing: border-box; }

body {
    font-family: "Arial", "Segoe UI", sans-serif;
    direction: ltr;
    text-align: left;
    background: #f5f6f8;
    color: #222;
    margin: 0;
    padding: 0;
}

.wrap {
    max-width: 780px;
    margin: 0 auto;
    padding: 24px 16px 60px;
}

header.site-header {
    text-align: center;
    padding: 30px 10px 10px;
}

header.site-header h1 {
    color: #2E4057;
    margin-bottom: 4px;
}

header.site-header p {
    color: #666;
    font-size: 15px;
}

.card-box {
    background: #fff;
    border-radius: 10px;
    padding: 22px 24px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.06);
    margin-bottom: 22px;
}

.step-title {
    font-size: 17px;
    font-weight: bold;
    color: #2E4057;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.step-num {
    background: #2E4057;
    color: #fff;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
}

.btn {
    display: inline-block;
    background: #2E4057;
    color: #fff !important;
    text-decoration: none;
    padding: 11px 22px;
    border-radius: 6px;
    font-size: 15px;
    border: none;
    cursor: pointer;
}

.btn:hover { background: #1c2a3a; }

.btn-secondary {
    background: #eee;
    color: #333 !important;
}

.btn-secondary:hover { background: #ddd; }

input[type="file"] {
    display: block;
    margin: 10px 0 18px;
    padding: 10px;
    border: 1px dashed #aaa;
    border-radius: 6px;
    width: 100%;
    background: #fafafa;
}

.templates-grid {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    margin: 12px 0 20px;
}

.template-option {
    flex: 1 1 150px;
    border: 2px solid #ddd;
    border-radius: 8px;
    padding: 12px;
    cursor: pointer;
    text-align: center;
    transition: border-color 0.15s;
}

.template-option:hover { border-color: #9aa7b5; }

.template-option input { display: none; }

.template-option.selected,
.template-option:has(input:checked) {
    border-color: #2E4057;
    background: #eef1f5;
}

.template-preview {
    height: 70px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mini-card { width: 30px; height: 40px; border: 1px solid #2E4057; border-radius: 3px; margin: 0 2px; display: inline-block; }
.mini-line { width: 60px; height: 6px; background: #2E4057; margin: 3px auto; border-radius: 2px; }
.mini-label { width: 26px; height: 34px; border: 1px dashed #2E4057; border-radius: 2px; margin: 0 2px; display: inline-block; }

.template-option span.opt-title { font-size: 13px; font-weight: bold; color: #333; }

.error-box {
    background: #fdecea;
    border: 1px solid #f5c2c0;
    color: #a12622;
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 18px;
    font-size: 14px;
}

footer.site-footer {
    text-align: center;
    color: #999;
    font-size: 12px;
    margin-top: 30px;
}

/* ---------- Nav, wider wraps ---------- */

.wrap-narrow { max-width: 420px; }
.wrap-wide { max-width: 1100px; }

.site-nav {
    display: flex;
    align-items: center;
    gap: 16px;
    background: #fff;
    padding: 12px 20px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.06);
    margin: 16px 0;
    flex-wrap: wrap;
}

.site-nav a { color: #2E4057; text-decoration: none; font-weight: bold; font-size: 14px; }
.site-nav a:hover { text-decoration: underline; }
.nav-spacer { flex: 1; }
.nav-user { color: #888; font-size: 13px; }

/* ---------- Messages ---------- */

.success-box {
    background: #e9f7ef;
    border: 1px solid #b7e4c7;
    color: #1e7b45;
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 18px;
    font-size: 14px;
}

/* ---------- Forms ---------- */

.form-label { display: block; font-size: 13px; color: #555; margin-bottom: 4px; }

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
}

.form-grid input, .form-grid select {
    width: 100%;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 13px;
}

/* ---------- Dashboard ---------- */

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
}

.dash-card { text-decoration: none; color: inherit; display: block; }
.dash-card p { color: #666; font-size: 13px; margin: 6px 0 0; }

/* ---------- Table ---------- */

.table-scroll { overflow-x: auto; }

table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data-table th { background: #2E4057; color: #fff; padding: 8px 10px; text-align: left; }
table.data-table td { padding: 7px 10px; border-bottom: 1px solid #eee; }
table.data-table tr:nth-child(even) td { background: #f7f8fa; }

.row-actions { white-space: nowrap; }

.btn-small {
    display: inline-block;
    background: #eef1f5;
    color: #2E4057;
    border: none;
    padding: 5px 10px;
    border-radius: 5px;
    font-size: 12px;
    cursor: pointer;
    text-decoration: none;
}
.btn-small:hover { background: #dde3ea; }
.btn-danger { background: #fdecea; color: #a12622; }
.btn-danger:hover { background: #f8d7d4; }

/* ---------- Designer ---------- */

.preset-list { display: flex; flex-wrap: wrap; gap: 10px; }
.preset-chip {
    display: flex;
    align-items: center;
    gap: 4px;
    background: #f4f6f8;
    border-radius: 6px;
    padding: 3px;
}
.preset-chip.active .btn-small { background: #2E4057; color: #fff; }

.designer-layout {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    align-items: flex-start;
}

.designer-canvas-wrap { flex: 2 1 400px; }
.designer-side-panel { flex: 1 1 260px; min-width: 240px; }

.tile-canvas {
    position: relative;
    background: #fafbfc;
    border: 1px solid #99a7b5;
    outline: 1px dashed #ccc;
    max-width: 100%;
}

.field-box {
    position: absolute;
    box-sizing: border-box;
    border: 1px solid #2E4057;
    background: rgba(46, 64, 87, 0.06);
    cursor: move;
    overflow: hidden;
    padding: 1px 2px;
    direction: rtl;
}

.field-box.selected {
    border: 2px solid #d6532c;
    background: rgba(214, 83, 44, 0.1);
    z-index: 2;
}

.field-box.pulling-out {
    border: 2px dashed #c0392b;
    background: rgba(192, 57, 43, 0.12);
    opacity: 0.6;
    cursor: no-drop;
    z-index: 3;
}

.field-box-label {
    pointer-events: none;
    color: #333;
}

.resize-handle {
    position: absolute;
    width: 10px;
    height: 10px;
    right: -5px;
    bottom: -5px;
    background: #2E4057;
    border-radius: 2px;
    cursor: nwse-resize;
}

/* Explicitly left-to-right: Width on the left, Height on the right */
.tile-size-controls { margin-top: 10px; font-size: 13px; display: flex; flex-wrap: wrap; align-items: flex-end; gap: 16px; direction: ltr; }
#grid-inputs { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 16px; direction: ltr; }
/* Label stacked over its own box, so it reads the same left-to-right and right-to-left */
.size-field { display: flex; flex-direction: column; gap: 3px; }
.tile-size-controls input { padding: 4px; border: 1px solid #ccc; border-radius: 4px; }

.field-inspector label {
    display: block;
    font-size: 12px;
    color: #555;
    margin-bottom: 8px;
}
.field-inspector input, .field-inspector select {
    display: block;
    width: 100%;
    padding: 6px;
    border: 1px solid #ccc;
    border-radius: 5px;
    margin-top: 2px;
}
.inspector-title { font-weight: bold; color: #2E4057; margin-bottom: 8px; }

.visibility-row { display: block; font-size: 13px; margin-bottom: 4px; }

.muted-note { color: #888; font-size: 13px; }

.mode-toggle { display: flex; gap: 20px; margin: 8px 0 14px; font-size: 14px; }

/* ---------- Book preview ---------- */

.book-pager {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-bottom: 20px;
    font-size: 14px;
}
.book-pager .disabled { pointer-events: none; opacity: 0.4; }

.book-preview-frame {
    overflow-x: auto;
    padding: 10px 0 30px;
}

/* Same tile style as in the PDF (renderPrintHtml), so the preview matches */
.book-preview-frame .tile { border: 1px solid #2E4057; border-radius: 2mm; }
.book-preview-frame .tile-field { direction: rtl; }
