:root {
    --brand-green: #3DC9A7;
    --brand-green-dark: #2BA889;
    --brand-green-light: #e8faf6;
    --brand-gold: #c8a951;
    --brand-dark: #1f1f1f;
    --brand-gray: #6c757d;
    --radius-lg: 1rem;
}

* { box-sizing: border-box; }

body {
    font-family: "Segoe UI", "Microsoft JhengHei", "Noto Sans TC", sans-serif;
    background: #f4f6f8;
    color: var(--brand-dark);
}

.brand-logo,
.navbar-logo {
    max-height: 56px;
    width: auto;
}

.navbar-logo { max-height: 40px; }

.brand-navbar {
    background: linear-gradient(135deg, var(--brand-green-dark), var(--brand-green));
    box-shadow: 0 4px 20px rgba(19, 69, 41, 0.25);
}

.btn-brand {
    background: linear-gradient(135deg, var(--brand-green), var(--brand-green-dark));
    border: none;
    color: #fff;
}

.btn-brand:hover,
.btn-brand:focus {
    background: linear-gradient(135deg, var(--brand-green-dark), #238b72);
    color: #fff;
}

.admin-tabs .nav-link {
    border-radius: 999px;
    padding: .55rem 1.25rem;
    color: var(--brand-gray);
}

.admin-tabs .nav-link.active {
    background: var(--brand-green);
    color: #fff;
}

.login-page,
.install-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(circle at top right, rgba(27, 94, 59, 0.12), transparent 40%),
        linear-gradient(180deg, #eef3ef 0%, #f8faf9 100%);
}

.login-wrapper { width: min(100%, 440px); padding: 1rem; }

.login-card,
.install-page .card {
    border-radius: var(--radius-lg);
}

.table thead th {
    background: var(--brand-green-light);
    border-bottom: none;
    white-space: nowrap;
    font-size: .875rem;
}

.table td {
    font-size: .925rem;
    vertical-align: middle;
}

.badge-signed { background: #198754; }
.badge-unsigned { background: #6c757d; }
.badge-published { background: var(--brand-green); }
.badge-unpublished { background: #adb5bd; }

.template-editor {
    min-height: 420px;
    border: 1px solid #dee2e6;
    border-radius: .75rem;
    padding: 1rem 1.25rem;
    background: #fff;
    line-height: 1.8;
    overflow-wrap: anywhere;
}

.template-editor:focus {
    outline: none;
    border-color: var(--brand-green);
    box-shadow: 0 0 0 .2rem rgba(27, 94, 59, 0.15);
}

.merge-field {
    display: inline-block;
    background: #eef1f4;
    color: #495057;
    border: 1px dashed #adb5bd;
    border-radius: .35rem;
    padding: .1rem .45rem;
    margin: 0 .1rem;
    font-size: .875rem;
    user-select: none;
    cursor: not-allowed;
}

.merge-field-btn {
    border-radius: 999px;
}

.template-toolbar {
    padding: .5rem .75rem;
    background: var(--brand-green-light);
    border-radius: .75rem;
}

.merged-value {
    color: var(--brand-green-dark);
}

.contract-page {
    background: linear-gradient(180deg, #eef3ef 0%, #f8faf9 40%, #fff 100%);
    min-height: 100vh;
}

.contract-header {
    background: #fff;
    border-bottom: 3px solid var(--brand-green);
    box-shadow: 0 2px 12px rgba(0,0,0,.05);
}

.status-card,
.contract-paper {
    background: #fff;
    border-radius: var(--radius-lg);
    padding: 1.25rem;
}

@media (min-width: 768px) {
    .status-card,
    .contract-paper { padding: 2rem; }
}

.contract-paper {
    border: 1px solid #e9ecef;
}

.contract-paper h2,
.contract-paper h3 {
    color: var(--brand-green-dark);
}

.contract-paper ol,
.contract-paper ul {
    padding-left: 1.25rem;
}

.signature-pad-wrapper {
    border: 2px dashed #ced4da;
    border-radius: .75rem;
    background: #fcfcfc;
    touch-action: none;
}

.signature-pad-wrapper canvas {
    display: block;
    width: 100%;
    height: 220px;
}

.signed-card .signature-display img {
    max-width: 100%;
    max-height: 180px;
    border: 1px solid #dee2e6;
    border-radius: .5rem;
    background: #fff;
    padding: .5rem;
}

.contract-footer {
    border-top: 1px solid #e9ecef;
    background: rgba(255,255,255,.8);
}

.action-btn-group {
    display: flex;
    flex-wrap: nowrap;
    gap: .35rem;
    justify-content: flex-end;
}

.status-cell-inner {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: .35rem;
    min-width: 8.5rem;
}

.status-badges {
    display: flex;
    flex-wrap: wrap;
    gap: .35rem;
}

.saved-password-box {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .5rem .75rem;
    margin-bottom: .5rem;
    background: var(--brand-green-light);
    border: 1px solid rgba(61, 201, 167, 0.35);
    border-radius: .5rem;
}

.saved-password-box strong {
    color: var(--brand-green-dark);
    flex: 1;
    word-break: break-all;
}

.publish-switch {
    padding-top: .25rem;
}

.publish-switch .form-check-label {
    white-space: nowrap;
}

.contract-link-cell {
    display: flex;
    align-items: center;
    gap: .5rem;
    max-width: 16rem;
}

.countdown-text {
    font-size: .75rem;
    color: #dc3545;
    line-height: 1.4;
    white-space: nowrap;
}

.link-copy-text {
    font-size: .75rem;
    color: var(--brand-gray);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
    flex: 1;
}

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

.orders-table {
    min-width: 72rem;
    margin-bottom: 0;
}

.orders-table th,
.orders-table td {
    white-space: nowrap;
}

.orders-table .status-cell-inner,
.orders-table .status-badges {
    white-space: normal;
}

.orders-table .contract-link-cell {
    min-width: 14rem;
    max-width: 14rem;
}

.orders-table .action-btn-group {
    min-width: 11rem;
}

@media (max-width: 767.98px) {
    .table-responsive { font-size: .85rem; }
    .orders-table-wrap {
        max-width: 100%;
    }
    .action-btn-group .btn { padding: .25rem .5rem; font-size: .75rem; }
    .admin-tabs { flex-wrap: nowrap; overflow-x: auto; }
    .admin-tabs .nav-link { white-space: nowrap; }
    .modal-dialog { margin: .75rem; }
    .publish-switch .form-check-label {
        white-space: normal;
    }
}
