:root {
    --bg: #f1f5f2;
    --surface: #ffffff;
    --ink: #1a2a1f;
    --muted: #5a6b5f;
    --accent: #0f766e;
    --accent-strong: #0b5a55;
    --accent-soft: #d8ece9;
    --border: #d5dfd9;
    --warning: #d08700;
    --danger: #b42318;
    --success: #1f8f4f;
    --shadow: 0 14px 30px rgba(23, 42, 30, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Segoe UI", "Trebuchet MS", sans-serif;
    color: var(--ink);
    background: radial-gradient(circle at top right, #dceee5, #f1f5f2 35%, #edf2ef 100%);
}

a {
    color: var(--accent);
}

.app-shell {
    display: grid;
    grid-template-columns: 280px 1fr;
    min-height: 100vh;
}

.sidebar {
    background: linear-gradient(180deg, #133b36 0%, #0d2e2b 100%);
    color: #edf7f3;
    padding: 24px 18px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.brand-block h1 {
    margin: 0;
    font-size: 1.4rem;
    letter-spacing: 0.5px;
}

.brand-block p {
    margin: 6px 0 0;
    font-size: 0.86rem;
    color: #b0cbc2;
}

.sidebar-nav {
    display: grid;
    gap: 6px;
}

.nav-link {
    color: #dbe9e4;
    text-decoration: none;
    padding: 10px 12px;
    border-radius: 10px;
    transition: background 0.2s ease, transform 0.2s ease;
}

.nav-link:hover {
    background: rgba(220, 245, 237, 0.14);
    transform: translateX(2px);
}

.nav-link.active {
    background: rgba(220, 245, 237, 0.2);
    font-weight: 600;
}

.sidebar-footer {
    margin-top: auto;
}

.logout-button {
    display: inline-block;
    width: 100%;
    padding: 11px 12px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.12);
    color: #f7fbf9;
    text-decoration: none;
    text-align: center;
}

.main-content {
    padding: 24px 30px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 20px;
}

.topbar h2 {
    margin: 0;
    font-size: 1.35rem;
}

.topbar small {
    color: var(--muted);
}

.content-area {
    display: grid;
    gap: 18px;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 18px;
    box-shadow: var(--shadow);
}

.panel h3 {
    margin-top: 0;
}

.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
}

.form-grid {
    display: grid;
    gap: 12px;
}

.form-grid.two {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

label {
    display: grid;
    gap: 6px;
    font-size: 0.92rem;
    color: var(--muted);
}

input,
select,
textarea,
button {
    font: inherit;
}

input[type="text"],
input[type="email"],
input[type="number"],
input[type="password"],
input[type="date"],
input[type="file"],
select,
textarea {
    width: 100%;
    border: 1px solid var(--border);
    background: #fff;
    border-radius: 10px;
    padding: 10px 12px;
    color: var(--ink);
}

textarea {
    resize: vertical;
}

.button,
button {
    border: none;
    border-radius: 10px;
    padding: 10px 14px;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-weight: 600;
}

button:hover,
.button:hover {
    background: var(--accent-strong);
}

.button-muted {
    background: #e8efeb;
    color: #204132;
}

.button-danger {
    background: #c7372f;
}

.button-warning {
    background: #af7a11;
}

.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 12px;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
}

th,
td {
    padding: 10px 12px;
    border-bottom: 1px solid #edf1ee;
    text-align: left;
    font-size: 0.93rem;
}

th {
    background: #f8faf8;
    color: #486255;
}

.badge {
    display: inline-block;
    border-radius: 999px;
    padding: 4px 9px;
    font-size: 0.78rem;
    font-weight: 600;
}

.badge-success {
    background: #def5e4;
    color: #196d3c;
}

.badge-muted {
    background: #e8ecea;
    color: #4f5f56;
}

.badge-danger {
    background: #fde2df;
    color: #9a1d1d;
}

.flash {
    padding: 11px 14px;
    border-radius: 10px;
    border: 1px solid transparent;
    margin-bottom: 10px;
}

.flash-success {
    background: #e3f7ea;
    border-color: #b9eac9;
    color: #1f6b3a;
}

.flash-error,
.flash-danger {
    background: #fce8e6;
    border-color: #f2c5c0;
    color: #9f1f17;
}

.flash-warning {
    background: #fff5dc;
    border-color: #f0dfaa;
    color: #8a640e;
}

.flash-info {
    background: #e7f1fb;
    border-color: #c8dff4;
    color: #1f4b7b;
}

.stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
}

.stat-card {
    border-radius: 12px;
    padding: 14px;
    background: linear-gradient(145deg, #ffffff, #f6faf8);
    border: 1px solid var(--border);
}

.stat-card p {
    margin: 0;
    color: var(--muted);
}

.stat-card h4 {
    margin: 6px 0 0;
    font-size: 1.5rem;
}

.guest-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 18px;
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background: #fff;
    border-radius: 18px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    padding: 24px;
}

.auth-card h1 {
    margin: 0;
}

.auth-card p {
    margin-top: 6px;
    color: var(--muted);
}

.inline-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.text-style-toolbar .button {
    min-width: 74px;
}

.text-style-toolbar .button.active {
    background: #1f4f8f;
    color: #ffffff;
}

.small {
    font-size: 0.82rem;
    color: var(--muted);
}

.editor-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 16px;
}

.canva-top-toolbar {
    grid-column: 1 / -1;
    position: sticky;
    top: 8px;
    z-index: 8;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid #d0dbd5;
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(8px);
    box-shadow: 0 10px 22px rgba(22, 43, 33, 0.12);
    transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.canva-top-toolbar:hover {
    border-color: #b8cbc2;
    box-shadow: 0 14px 28px rgba(19, 41, 32, 0.16);
}

.canva-toolbar-group {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding-right: 10px;
    border-right: 1px solid #e1e8e4;
}

.canva-toolbar-group:last-child {
    border-right: none;
    padding-right: 0;
}

.canva-top-toolbar select,
.canva-top-toolbar input[type="number"] {
    width: auto;
    min-width: 120px;
    padding: 8px 10px;
}

.canva-top-toolbar input[type="color"] {
    width: 46px;
    min-width: 46px;
    height: 38px;
    padding: 2px;
}

.canva-top-toolbar .button {
    padding: 8px 11px;
}

.template-canvas {
    position: relative;
    overflow: auto;
    border: 1px dashed #9cb5ab;
    border-radius: 12px;
    min-height: 420px;
    background: #fff;
}

.template-canvas img {
    max-width: 100%;
    display: block;
}

.mapping-marker {
    position: absolute;
    min-width: 140px;
    min-height: 34px;
    padding: 6px 18px 6px 8px;
    border-radius: 8px;
    border: 1px dashed #0f766e;
    background: rgba(255, 255, 255, 0.78);
    color: #053431;
    cursor: grab;
    user-select: none;
    font-size: 0.84rem;
    box-shadow: 0 4px 12px rgba(10, 40, 31, 0.08);
    overflow: hidden;
}

.mapping-marker.active {
    border-color: #c7372f;
    background: rgba(255, 243, 241, 0.9);
}

.mapping-marker.editing {
    border-style: solid;
    border-color: #0b5a55;
    cursor: text;
    user-select: text;
}

.mapping-marker.editing .marker-main {
    user-select: text;
    -webkit-user-select: text;
}

.mapping-marker .marker-main {
    outline: none;
    white-space: normal;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    line-height: 1.2;
}

.mapping-marker.template-marker .marker-main {
    display: block;
    -webkit-line-clamp: unset;
    -webkit-box-orient: initial;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    line-height: 1.28;
    font-weight: 700;
    text-overflow: unset;
    overflow: hidden;
}

.mapping-marker .marker-meta {
    margin-top: 3px;
    font-size: 0.72rem;
    color: #5c7468;
}

.mapping-resize-handle {
    position: absolute;
    right: 4px;
    bottom: 4px;
    width: 10px;
    height: 10px;
    border-right: 2px solid #0f766e;
    border-bottom: 2px solid #0f766e;
    opacity: 0.85;
    cursor: nwse-resize;
}

.mapping-marker.active .mapping-resize-handle {
    border-color: #c7372f;
}

.preview-card {
    display: grid;
    gap: 10px;
    align-items: center;
}

.preview-card img {
    width: 100%;
    border-radius: 10px;
    border: 1px solid var(--border);
}

.progress-track {
    width: 100%;
    height: 10px;
    border-radius: 999px;
    overflow: hidden;
    background: #e7ece9;
}

.progress-fill {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, #0f766e, #2ea596);
    transition: width 0.3s ease;
}

@media (max-width: 1120px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: sticky;
        top: 0;
        z-index: 10;
    }

    .stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .editor-layout {
        grid-template-columns: 1fr;
    }

    .canva-top-toolbar {
        position: static;
    }
}

@media (max-width: 720px) {
    .main-content {
        padding: 16px;
    }

    .grid-2,
    .grid-3,
    .form-grid.two {
        grid-template-columns: 1fr;
    }

    .topbar {
        flex-direction: column;
        align-items: flex-start;
    }

    .stats {
        grid-template-columns: 1fr;
    }
}
